On 3/5/25 10:50 AM, Marek Polacek wrote:
On Tue, Mar 04, 2025 at 04:41:05PM -0500, Jason Merrill wrote:
On 3/4/25 3:26 PM, Marek Polacek wrote:
Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk?
-- >8 --
This PR complains that we issue a -Wnonnull even in a decltype.
Since we can't use cp_unevaluated_operand in c-common.cc, this
Would it make sense to check c_inhibit_evaluation_warnings instead?
Yes, I think that would be better, thanks.
Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk?
OK by me.
-- >8 --
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.
---
gcc/c-family/c-common.cc | 3 +++
gcc/testsuite/g++.dg/warn/Wnonnull16.C | 16 ++++++++++++++++
2 files changed, 19 insertions(+)
create mode 100644 gcc/testsuite/g++.dg/warn/Wnonnull16.C
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" }
+}
base-commit: ff505948631713d8c62523005059b10e25343617