Search code examples
c++gcc

Silence ambiguous reversed operator warning in gcc13


I have some 3rd party code I can't modify

GCC13 says

warning: C++20 says that these are ambiguous, even though the second is reversed

On clang I can do

#pragma GCC diagnostic ignored "-Wambiguous-reversed-operator"

But on gcc13 I can't figure out the pragma that silences the warning

// Some example that triggers the warning
template <typename>
struct S {
  friend bool operator==(S&&, const S&) { return true; }
  friend bool operator!=(S&&, const S&) { return true; }
};

using U = S<int>;
#pragma GCC diagnostic push
// #pragma GCC diagnostic ignored "-Wambiguous-reversed-operator" #<- works fine in clang
bool b = U{} == U{};
#pragma GCC diagnostic pop

https://godbolt.org/z/8h1fP4xW8


Solution

  • That warning does not have an associated command line option in gcc.

    It is being issued as a "pedwarn":

    pedwarn is for code that is accepted by GCC but it should be rejected or diagnosed according to the current standard, or it conflicts with the standard (either the default or the one selected by -std=).

    possibly gcc does not give you the option to silence it because the standard is asking for a diagnostic here.

    You can only choose to make it an error or a warning. I guess you will not be able to compile this code with -Werror.

    The relevant bit of gcc source code: https://codebrowser.dev/gcc/gcc/cp/call.cc.html#12724

    (note the lack of test for a specific warning enabled surrounding the issuing code)