Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Ambiguous equality/inequality operators under C++20 #631

@tonyelewis

Description

@tonyelewis

Running clang++ -x c++ -std=c++2a -isystem include include/cereal/archives/json.hpp with a trunk version of Clang in the root of the cereal repo, gives:

In file included from include/cereal/archives/json.hpp:67:
include/cereal/external/rapidjson/document.h:813:58: error: use of overloaded operator '!=' is ambiguous (with operand types 'rapidjson::GenericValue<rapidjson::UTF8<char>, rapidjson::MemoryPoolAllocator<rapidjson::CrtAllocator> >::MemberIterator' (aka 'rapidjson::GenericMemberIterator<false, rapidjson::UTF8<char>, rapidjson::MemoryPoolAllocator<rapidjson::CrtAllocator> >') and 'rapidjson::GenericValue<rapidjson::UTF8<char>, rapidjson::MemoryPoolAllocator<rapidjson::CrtAllocator> >::MemberIterator')
                for (MemberIterator m = MemberBegin(); m != MemberEnd(); ++m)
                                                       ~ ^  ~~~~~~~~~~~
include/cereal/external/rapidjson/document.h:2150:5: note: in instantiation of member function 'rapidjson::GenericValue<rapidjson::UTF8<char>, rapidjson::MemoryPoolAllocator<rapidjson::CrtAllocator> >::~GenericValue' requested here
    GenericDocument(Allocator* allocator = 0, size_t stackCapacity = kDefaultStackCapacity, StackAllocator* stackAllocator = 0) :
    ^
include/cereal/archives/json.hpp:435:7: note: in instantiation of member function 'rapidjson::GenericDocument<rapidjson::UTF8<char>, rapidjson::MemoryPoolAllocator<rapidjson::CrtAllocator>, rapidjson::CrtAllocator>::GenericDocument' requested here
      JSONInputArchive(std::istream & stream) :
      ^
include/cereal/external/rapidjson/document.h:179:10: note: candidate function
    bool operator!=(ConstIterator that) const { return ptr_ != that.ptr_; }
         ^
include/cereal/external/rapidjson/document.h:178:10: note: candidate function
    bool operator==(ConstIterator that) const { return ptr_ == that.ptr_; }
         ^
include/cereal/external/rapidjson/document.h:178:10: note: candidate function (with reversed parameter order)
1 error generated.

AFAIU, the reworking of comparisons in C++20 means that the new language must now reject some previously acceptable code for causing ambiguities between comparison operators that the compiler could consider (eg see discussion here https://bugs.llvm.org/show_bug.cgi?id=43765#c4 ).

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions