https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115580
Bug ID: 115580 Summary: decltype of nullptr error with -Werror=nonnull Product: gcc Version: 14.1.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: marcpawl at gmail dot com Target Milestone: --- -Werror=nonnull returns error when using nullptr to get type of member function. Even though we are using -Werror=nonnull, there should be no diagnostic since the function is never evaluated, and it is non-virtual. https://godbolt.org/z/3oh1199Wh https://stackoverflow.com/questions/5580253/how-do-i-get-the-return-type-of-a-member-function-without-an-object class WithMember { public: int foo(); }; decltype(((WithMember*)nullptr)->foo()) footype; <source>:7:37: error: 'this' pointer is null [-Werror=nonnull] 7 | decltype(((WithMember*)nullptr)->foo()) footype; | ~~~~~~~~~~~~~~~~~~~~~~~~~~~^~ <source>:4:7: note: in a call to non-static member function 'int WithMember::foo()' 4 | int foo(); | ^~~ <source>:7:37: error: 'this' pointer is null [-Werror=nonnull] 7 | decltype(((WithMember*)nullptr)->foo()) footype; | ~~~~~~~~~~~~~~~~~~~~~~~~~~~^~ <source>:4:7: note: in a call to non-static member function 'int WithMember::foo()' 4 | int foo(); | ^~~ cc1plus: some warnings being treated as errors Compiler returned: 1