From: Marek Polacek Date: Tue, 4 Mar 2025 18:07:27 +0000 (-0500) Subject: c++: disable -Wnonnull in unevaluated context [PR115580] X-Git-Tag: basepoints/gcc-16~1714 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=459c8a55567b06522e4b9cc0a4ef62f9d3024526;p=thirdparty%2Fgcc.git c++: disable -Wnonnull in unevaluated context [PR115580] This PR complains that we issue a -Wnonnull even in a decltype. This fix disables even -Wformat and -Wrestrict. I think that's fine. PR c++/115580 gcc/c-family/ChangeLog: * c-common.cc (check_function_arguments): Return early if c_inhibit_evaluation_warnings. gcc/testsuite/ChangeLog: * g++.dg/warn/Wnonnull16.C: New test. Reviewed-by: Jason Merrill --- diff --git a/gcc/c-family/c-common.cc b/gcc/c-family/c-common.cc index 49508fe9ee6..587d76461e9 100644 --- a/gcc/c-family/c-common.cc +++ b/gcc/c-family/c-common.cc @@ -6261,6 +6261,9 @@ check_function_arguments (location_t loc, const_tree fndecl, const_tree fntype, { bool warned_p = false; + if (c_inhibit_evaluation_warnings) + return warned_p; + /* Check for null being passed in a pointer argument that must be non-null. In C++, this includes the this pointer. We also need to do this if format checking is enabled. */ diff --git a/gcc/testsuite/g++.dg/warn/Wnonnull16.C b/gcc/testsuite/g++.dg/warn/Wnonnull16.C new file mode 100644 index 00000000000..8740f351ac7 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wnonnull16.C @@ -0,0 +1,16 @@ +// PR c++/115580 +// { dg-do compile { target c++11 } } + +class WithMember { +public: + int foo(); +}; + +decltype(((WithMember*)nullptr)->foo()) footype; // { dg-bogus "pointer is null" } + +int f(void*) __attribute__((nonnull)); + +void g() +{ + [[maybe_unused]] decltype(f(nullptr)) b; // { dg-bogus "non-null" } +}