Lenient overhead resolutions and where to find them in the manual

2024-01-29 Thread Martin Licht via Gcc
GCC seems to have a non-standard lenient C++ overload resolution that is 
not documented (or easy to find in the manual).


The following C++ code compiles with GCC. However, it produces a warning 
about an ambiguous overload that apparently is not acceptable by the 
standard. Clang and MVSC simply reject the code because of the ambiguous 
overload.


```
// reduced example
#include 
using namespace std;
struct A{};
struct B: public A {};
struct C{};
struct D{ D() = default; D(const C&){}; };

void p( A&, const C& ){ cout << "AC\n"; };
void p( B&, const D& ){ cout << "BD\n"; };

int main() {
    B b; C c;
    p(b,c); // ambiguous call
    return 0;
}
```

GCC detects ambiguity in which `p` to choose: either cast from derived 
class B& to base class A& or construct D from C.


```
$ g++ test.cpp
test.cpp: In function ‘int main()’:
test.cpp:51:10: warning: ISO C++ says that these are ambiguous, even 
though the worst conversion for the first is better than the worst 
conversion for the second:

   51 | p(b,c);
  | ~^
test.cpp:12:6: note: candidate 1: ‘void p(A&, const C&)’
   12 | void p( A&, const C& ){ cout << "AC\n"; };
  |  ^
test.cpp:15:6: note: candidate 2: ‘void p(B&, const D&)’
   15 | void p( B&, const D& ){ cout << "BD\n"; };
  |  ^
```

With `-pedantic` it does not compile anymore. I subjectively agree with 
GCC that the first choice is better than the second. But not everyone 
may do so. Is there a documentation of all these deviations from the 
standard?




Disable warning about #warning

2024-12-31 Thread Martin Licht via Gcc
When compiling in pedantic mode, using the #warning directive emits not 
only the warning itself but also


`` warning: #warning is a GCC extension``

That is true to form, of course, since the pedantic switch is on. But it 
is desirable to switch off this particular pedantic warning. The 
explicit #warning should remain visible, of course.


There seems to be no known way to switch off the above warning. On a 
more general level, I think most people would appreciate ramping up the 
strictness with -pedantic but still cherry picking what errors or 
warnings to disable.


I am aware that C23 and C++23 will have #warning in the standard.

Consider this both a request for help and a feature request.