[Bug c++/96877] Erroneous warning when default initializing function pointer types defined using std::declval
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96877 --- Comment #6 from Ian Henriksen --- Thanks, this makes sense. I originally got this idea from https://stackoverflow.com/a/27489923. The discussion there implied there was some kind of ambiguity in the standard and showed some examples where exception specification appeared to be carried through as a part of the type in order to satisfy the rules about assigning to function pointers with noexcept specifiers. After revisiting their examples I've found that there's actually inconsistency with how actual values are handled vs how values from std::declval are handled. For example, the following is accepted as valid C++11 by both gcc and clang: #include #include void (*function_ptr)(void *) noexcept = nullptr; using function_type = decltype(function_ptr); using function_type_2 = std::remove_reference())>::type; function_type thing1; function_type_2 thing2; static_assert(noexcept(thing1(nullptr)), ""); static_assert(!noexcept(thing2(nullptr)), ""); static_assert(std::is_same::value, ""); See https://godbolt.org/z/YbzGM3. It's not obvious to me what the correct behavior would be based off of the actual wording of the standard, but this is bizarre. This behavior is consistent across clang and the last 3 major gcc releases, but the implicit inclusion of the exception specification in the type does not seem like something that should be relied upon.
[Bug c++/96877] Erroneous warning when default initializing function pointer types defined using std::declval
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96877 --- Comment #4 from Ian Henriksen --- It's worth noting that, with g++ using function_type = void (*)(void*) noexcept; actually works, but typedef void(*function_type)(void*) noexcept; does not. clang++ rejects both though.
[Bug c++/96877] Erroneous warning when default initializing function pointer types defined using std::declval
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96877 --- Comment #3 from Ian Henriksen --- The goal of doing it that way was get the exception specification onto the pointer type in C++11 and C++14. The intent was to get the equivalent of typedef void(*function_type)(void*) noexcept; but with standards earlier than C++17.
[Bug c++/96877] Erroneous warning when default initializing function pointer types defined using std::declval
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96877 Ian Henriksen changed: What|Removed |Added Status|UNCONFIRMED |RESOLVED Resolution|--- |INVALID --- Comment #1 from Ian Henriksen --- Actually this is my mistake. std::declval returns by reference, so this is actually a reference type and the compiler is right to warn about the bad initialization. In this case the correct thing to do is to remove the reference after getting the type from decltype.
[Bug c++/96877] New: Erroneous warning when default initializing function pointer types defined using std::declval
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96877 Bug ID: 96877 Summary: Erroneous warning when default initializing function pointer types defined using std::declval Product: gcc Version: 10.2.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: insertinterestingnamehere at gmail dot com Target Milestone: --- When compiling the following with -Wextra (C++11 and later, all recent version of gcc) the compiler emits an erroneous warning about binding a temporary in a constructor. Note: this works fine if function_type is declared as a plain typedef instead of using decltype and std::declval. See https://godbolt.org/z/sjKdP5. #include using function_type = decltype(std::declval()); struct S { function_type fptr = nullptr; }; int main() { S thing; }
[Bug c++/85775] New: False positive with -Wparentheses
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85775 Bug ID: 85775 Summary: False positive with -Wparentheses Product: gcc Version: 8.1.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: insertinterestingnamehere at gmail dot com Target Milestone: --- g++ 8.1 warns about unnecessary parentheses in some cases where they are actually needed to designate something as a single argument to a macro. Here's a minimal example: #define M(x) x template struct A { static const volatile char *M(B); }; template const volatile char *M((A<T, S>::B)) = nullptr; As it stands, the compiler warns that the double parentheses are unnecessary, but if they are removed the preprocessor complains that two arguments are being passed to a macro that only expects one. The only work around, for now, is to locally disable the warning with pragmas.