aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarek Polacek <polacek@redhat.com>2025-03-04 13:07:27 -0500
committerMarek Polacek <polacek@redhat.com>2025-03-05 16:03:30 -0500
commit459c8a55567b06522e4b9cc0a4ef62f9d3024526 (patch)
tree0b1917184ad1b536949170a7dc01759befeb173c
parent24ea4539300d4926d9f073822e68f0d2f369452d (diff)
downloadgcc-459c8a55567b06522e4b9cc0a4ef62f9d3024526.zip
gcc-459c8a55567b06522e4b9cc0a4ef62f9d3024526.tar.gz
gcc-459c8a55567b06522e4b9cc0a4ef62f9d3024526.tar.bz2
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 <jason@redhat.com>
-rw-r--r--gcc/c-family/c-common.cc3
-rw-r--r--gcc/testsuite/g++.dg/warn/Wnonnull16.C16
2 files changed, 19 insertions, 0 deletions
diff --git a/gcc/c-family/c-common.cc b/gcc/c-family/c-common.cc
index 49508fe..587d764 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 0000000..8740f35
--- /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" }
+}