aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--gcc/c-family/ChangeLog7
-rw-r--r--gcc/c-family/c-attribs.c2
-rw-r--r--gcc/testsuite/ChangeLog7
-rw-r--r--gcc/testsuite/c-c++-common/nonnull-3.c11
-rw-r--r--gcc/testsuite/g++.dg/warn/Wnonnull3.C15
5 files changed, 41 insertions, 1 deletions
diff --git a/gcc/c-family/ChangeLog b/gcc/c-family/ChangeLog
index b14cb0d..a644773 100644
--- a/gcc/c-family/ChangeLog
+++ b/gcc/c-family/ChangeLog
@@ -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.
diff --git a/gcc/c-family/c-attribs.c b/gcc/c-family/c-attribs.c
index 8058a65..f2a88e1 100644
--- a/gcc/c-family/c-attribs.c
+++ b/gcc/c-family/c-attribs.c
@@ -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))
{
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index bc2bc4a..84d8774 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -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
index 0000000..d2ccb24
--- /dev/null
+++ b/gcc/testsuite/c-c++-common/nonnull-3.c
@@ -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
index 0000000..d1918ef
--- /dev/null
+++ b/gcc/testsuite/g++.dg/warn/Wnonnull3.C
@@ -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" }
+}