This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
C++ patch to support attribute nonnull
- From: "Joseph S. Myers" <jsm at polyomino dot org dot uk>
- To: gcc-patches at gcc dot gnu dot org
- Date: Tue, 29 Jun 2004 15:19:28 +0000 (UTC)
- Subject: C++ patch to support attribute nonnull
The C++ front end currently only gets the format attribute checking
and not that for nonnull attributes. This patch fixes that. It
depends (textually, not logically) on my previous patch
<http://gcc.gnu.org/ml/gcc-patches/2004-06/msg02366.html> removing a
parameter from the interface to the format checking code as it changes
again code in the C++ front end that was changed by that patch.
Bootstrapped with no regressions on i686-pc-linux-gnu. OK to commit?
cp:
2004-06-29 Joseph S. Myers <jsm@polyomino.org.uk>
* call.c (build_over_call), typeck.c (build_function_call): Call
check_function_arguments instead of check_function_format.
testsuite:
2004-06-29 Joseph S. Myers <jsm@polyomino.org.uk>
* g++.dg/warn/nonnull1.C: New test.
--
Joseph S. Myers http://www.srcf.ucam.org/~jsm28/gcc/
jsm@polyomino.org.uk (personal mail)
jsm28@gcc.gnu.org (Bugzilla assignments and CCs)
diff -rupN gcc.orig/cp/call.c gcc/cp/call.c
--- gcc.orig/cp/call.c 2004-06-27 21:50:09.000000000 +0000
+++ gcc/cp/call.c 2004-06-28 22:51:34.000000000 +0000
@@ -4716,9 +4716,8 @@ build_over_call (struct z_candidate *can
converted_args = nreverse (converted_args);
- if (warn_format)
- check_function_format (TYPE_ATTRIBUTES (TREE_TYPE (fn)),
- converted_args);
+ check_function_arguments (TYPE_ATTRIBUTES (TREE_TYPE (fn)),
+ converted_args);
/* Avoid actually calling copy constructors and copy assignment operators,
if possible. */
diff -rupN gcc.orig/cp/typeck.c gcc/cp/typeck.c
--- gcc.orig/cp/typeck.c 2004-06-27 21:50:19.000000000 +0000
+++ gcc/cp/typeck.c 2004-06-28 22:52:27.000000000 +0000
@@ -2483,10 +2483,10 @@ build_function_call (tree function, tree
if (coerced_params == error_mark_node)
return error_mark_node;
- /* Check for errors in format strings. */
+ /* Check for errors in format strings and inappropriately
+ null parameters. */
- if (warn_format)
- check_function_format (TYPE_ATTRIBUTES (fntype), coerced_params);
+ check_function_arguments (TYPE_ATTRIBUTES (fntype), coerced_params);
return build_cxx_call (function, coerced_params);
}
diff -rupN gcc.orig/testsuite/g++.dg/warn/nonnull1.C gcc/testsuite/g++.dg/warn/nonnull1.C
--- gcc.orig/testsuite/g++.dg/warn/nonnull1.C 1970-01-01 00:00:00.000000000 +0000
+++ gcc/testsuite/g++.dg/warn/nonnull1.C 2004-06-28 22:59:35.000000000 +0000
@@ -0,0 +1,16 @@
+// Test that "nonnull" attribute works for C++.
+// Origin: Joseph Myers <jsm@polyomino.org.uk>
+// { dg-do compile }
+// { dg-options "-Wall" }
+
+// The "nonnull" attribute is thoroughly tested for C, so here we
+// simply test that it works at all, as at one point the relevant
+// checking code was only called for C.
+
+extern void f (char *) __attribute__((nonnull));
+
+void
+g ()
+{
+ f (0); // { dg-warning "null" "null argument" }
+}