[SERVER-77924] Spurious warning ("note") from data_range.h about BSONElement::data Created: 08/Jun/23  Updated: 29/Oct/23  Resolved: 12/Jun/23

Status: Closed
Project: Core Server
Component/s: None
Affects Version/s: None
Fix Version/s: 7.1.0-rc0

Type: Improvement Priority: Major - P3
Reporter: Billy Donahue Assignee: Billy Donahue
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Assigned Teams:
Service Arch
Backwards Compatibility: Fully Compatible
Sprint: Service Arch 2023-06-12
Participants:

 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".



 Comments   
Comment by Githook User [ 12/Jun/23 ]

Author:

{'name': 'Billy Donahue', 'email': 'billy.donahue@mongodb.com', 'username': 'BillyDonahue'}

Message: SERVER-77924 data_range.h: cleaner concept checks to avoid compiler notes
Branch: master
https://github.com/mongodb/mongo/commit/81f3bc73b0853d958713c26f37c8ceff4f4819de

Generated at Thu Feb 08 06:36:59 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.