re PR c++/79962 (ICE nonnull_check_p on a function template with a type-dependent...
authorMarek Polacek <polacek@redhat.com>
Thu, 9 Mar 2017 22:45:39 +0000 (22:45 +0000)
committerMarek Polacek <mpolacek@gcc.gnu.org>
Thu, 9 Mar 2017 22:45:39 +0000 (22:45 +0000)
PR c++/79962
PR c++/79984
* c-attribs.c (handle_nonnull_attribute): Save the result of default
conversion to the attribute list.

* c-c++-common/nonnull-3.c: New test.
* g++.dg/warn/Wnonnull3.C: New test.

From-SVN: r246016

gcc/c-family/ChangeLog
gcc/c-family/c-attribs.c
gcc/testsuite/ChangeLog
gcc/testsuite/c-c++-common/nonnull-3.c [new file with mode: 0644]
gcc/testsuite/g++.dg/warn/Wnonnull3.C [new file with mode: 0644]

index b14cb0d64fe7eef8db6af391fac222630d9e4312..a6447738f6bb1340ab12dcf2f3affe4f43a0746b 100644 (file)
@@ -1,3 +1,10 @@
+2017-03-09  Marek Polacek  <polacek@redhat.com>
+
+       PR c++/79962
+       PR c++/79984
+       * c-attribs.c (handle_nonnull_attribute): Save the result of default
+       conversion to the attribute list.
+
 2017-03-09  Martin Liska  <mliska@suse.cz>
 
        * c-ada-spec.c (macro_length): Increment value instead of a pointer.
index 8058a6518c53a1f527a29ea14df63231b340d8e8..f2a88e147ba5f0ce3d88bff105f341bd10f0fcac 100644 (file)
@@ -2813,7 +2813,7 @@ handle_nonnull_attribute (tree *node, tree ARG_UNUSED (name),
       tree arg = TREE_VALUE (args);
       if (arg && TREE_CODE (arg) != IDENTIFIER_NODE
          && TREE_CODE (arg) != FUNCTION_DECL)
-       arg = default_conversion (arg);
+       TREE_VALUE (args) = arg = default_conversion (arg);
 
       if (!get_nonnull_operand (arg, &arg_num))
        {
index bc2bc4a54378a1ab7d6e58025d5e44e3e19903c9..84d87741e5d125388864438c23264ce96b04376a 100644 (file)
@@ -1,3 +1,10 @@
+2017-03-09  Marek Polacek  <polacek@redhat.com>
+
+       PR c++/79962
+       PR c++/79984
+       * c-c++-common/nonnull-3.c: New test.
+       * g++.dg/warn/Wnonnull3.C: New test.
+
 2017-03-09  Matthew Fortune  <matthew.fortune@imgtec.com>
 
        * gcc.target/mips/lxc1-sxc1-1.c: Use -mhard-float.
diff --git a/gcc/testsuite/c-c++-common/nonnull-3.c b/gcc/testsuite/c-c++-common/nonnull-3.c
new file mode 100644 (file)
index 0000000..d2ccb24
--- /dev/null
@@ -0,0 +1,11 @@
+/* PR c++/79984 */
+/* { dg-do compile } */
+/* { dg-options "-Wnonnull-compare" } */
+
+enum { r = 1 };
+
+__attribute__ ((nonnull (r))) int
+f (int *p)
+{
+  return p == 0; /* { dg-warning "nonnull argument 'p' compared to NULL" } */
+}
diff --git a/gcc/testsuite/g++.dg/warn/Wnonnull3.C b/gcc/testsuite/g++.dg/warn/Wnonnull3.C
new file mode 100644 (file)
index 0000000..d1918ef
--- /dev/null
@@ -0,0 +1,15 @@
+// PR c++/79962
+// { dg-options "-Wnonnull" }
+
+template <class T>
+__attribute__ ((__nonnull__ (T::i))) void f (typename T::U) { }
+
+struct S1 { enum { i = 1 }; typedef void* U; };
+struct S2 { static const int i = 1; typedef void* U; };
+
+void
+g ()
+{
+  f<S1>(0); // { dg-warning "null argument where non-null required" }
+  f<S2>(0); // { dg-warning "null argument where non-null required" }
+}