{
warned = warning_at (loc, OPT_Wnonnull,
"%qs pointer null", "this");
- if (pctx->fndecl)
+ if (warned && pctx->fndecl)
inform (DECL_SOURCE_LOCATION (pctx->fndecl),
"in a call to non-static member function %qD",
pctx->fndecl);
warned = warning_at (loc, OPT_Wnonnull,
"argument %u null where non-null expected",
(unsigned) param_num);
- if (pctx->fndecl)
+ if (warned && pctx->fndecl)
inform (DECL_SOURCE_LOCATION (pctx->fndecl),
"in a call to function %qD declared %qs",
pctx->fndecl, "nonnull");
--- /dev/null
+/* PR c++/96310 - Ignoring -Wnonnull via pragma gcc diagnostics still produces
+ an unwanted note
+ { dg-do compile }
+ { dg-options "-Wall" } */
+
+struct C {
+ void f (); // { dg-message "in a call" }
+ void g (); // { dg-bogus "in a call" }
+};
+
+void f ()
+{
+ static_cast<C*>(0)->f (); // { dg-warning "\\\[-Wnonnull" }
+}
+
+void g ()
+{
+#pragma GCC diagnostic ignored "-Wnonnull"
+ static_cast<C*>(0)->g ();
+}