Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-77924

Spurious warning ("note") from data_range.h about BSONElement::data

    XMLWordPrintableJSON

Details

    • Icon: Improvement Improvement
    • Resolution: Fixed
    • Icon: Major - P3 Major - P3
    • 7.1.0-rc0
    • None
    • None
    • None
    • Service Arch
    • Fully Compatible
    • Service Arch 2023-06-12

    Description

      This happens in a widely used header (data_range.h), so every build sees a LOT of these "note" lines, which can "cry wolf" and mask more legitimate warnings.

      This is a compiler "note". Compiler notes look like warnings but aren't.

      They're disruptive and probably easily avoidable perhaps with some improved metaprogramming.

      In file included from src/mongo/crypto/fle_crypto.h:40,
                       from src/mongo/db/query/fle/range_validator.h:31,
                       from src/mongo/db/query/fle/range_validator.cpp:30:
      src/mongo/base/data_range.h: In substitution of 'template<class T> struct mongo::ConstDataRange::ContiguousContainerOfByteLike<T, std::void_t<decltype (declval<T>().data()), typename std::enable_if<(isByteV<typename T::value_type> && mongo::ConstDataRange::HasDataSize<T, void>::value), void>::type> > [with T = mongo::BSONElement]':
      src/mongo/base/data_range.h:112:97:   required by substitution of 'template<class Container, typename std::enable_if<mongo::ConstDataRange::ContiguousContainerOfByteLike<Container>::value, int>::type <anonymous> > mongo::ConstDataRange::ConstDataRange(const Container&, std::ptrdiff_t) [with Container = mongo::BSONElement; typename std::enable_if<mongo::ConstDataRange::ContiguousContainerOfByteLike<Container>::value, int>::type <anonymous> = <missing>]'
      src/mongo/db/query/fle/encrypted_predicate.h:71:76:   required from 'T mongo::fle::parseFindPayload(mongo::fle::BSONValue) [with T = mongo::ParsedFindRangePayload; mongo::fle::BSONValue = std::variant<mongo::BSONElement, std::reference_wrapper<mongo::Value> >]'
      src/mongo/db/query/fle/range_validator.cpp:96:60:   required from here
      src/mongo/base/data_range.h:69:48: note: field 'const char* mongo::BSONElement::data' can be accessed via 'const char* mongo::BSONElement::rawdata() const'
         69 |         std::void_t<decltype(std::declval<T>().data()),
            |                              ~~~~~~~~~~~~~~~~~~^~~~
            |                              rawdata()
      

      The problem is that data_layer.h is trying to invoke the data member of T as a detection concept check. BSONElement has a data member, but it's a private const char*. The warning is "helpfully" suggesting that if you want to access the "data" member it's available with the "rawdata" accessor function. But that's not what we're interested in. We don't want BSONElement to be interpreted as a data layer ContiguousContainerOfByteLike at all.

      The old school concept check is here:

          template <typename T, typename = void>
          struct ContiguousContainerOfByteLike : std::false_type {};
       
          template <typename T>
          struct ContiguousContainerOfByteLike<
              T,
              std::void_t<decltype(std::declval<T>().data()),
                          std::enable_if_t<isByteV<typename T::value_type> && HasDataSize<T>::value>>>
              : std::true_type {};
      

      can be modernized significantly to C+17/C+20 detection idioms which could be designed to avoid triggering this "note".

      Attachments

        Activity

          People

            billy.donahue@mongodb.com Billy Donahue
            billy.donahue@mongodb.com Billy Donahue
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: