re PR c++/52718 (-Wzero-as-null-pointer-constant: misleading location for 0 as defaul...
authorPaolo Carlini <paolo.carlini@oracle.com>
Thu, 29 Mar 2012 22:45:46 +0000 (22:45 +0000)
committerPaolo Carlini <paolo@gcc.gnu.org>
Thu, 29 Mar 2012 22:45:46 +0000 (22:45 +0000)
/cp
2012-03-29  Paolo Carlini  <paolo.carlini@oracle.com>

PR c++/52718
* decl.c (check_default_argument): With -Wzero-as-null-pointer-constant
warn for a zero as null pointer constant default argument.

/testsuite
2012-03-29  Paolo Carlini  <paolo.carlini@oracle.com>

PR c++/52718
* g++.dg/warn/Wzero-as-null-pointer-constant-5.C: New.

From-SVN: r185983

gcc/cp/ChangeLog
gcc/cp/decl.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/warn/Wzero-as-null-pointer-constant-5.C [new file with mode: 0644]

index af7fa2d..7e4e549 100644 (file)
@@ -1,3 +1,9 @@
+2012-03-29  Paolo Carlini  <paolo.carlini@oracle.com>
+
+       PR c++/52718
+       * decl.c (check_default_argument): With -Wzero-as-null-pointer-constant
+       warn for a zero as null pointer constant default argument.
+
 2012-03-29  Jason Merrill  <jason@redhat.com>
 
        PR c++/52685
index 8c5fda6..a89523d 100644 (file)
@@ -10596,6 +10596,17 @@ check_default_argument (tree decl, tree arg)
       return error_mark_node;
     }
 
+  if (warn_zero_as_null_pointer_constant
+      && c_inhibit_evaluation_warnings == 0
+      && (POINTER_TYPE_P (decl_type) || TYPE_PTR_TO_MEMBER_P (decl_type))
+      && null_ptr_cst_p (arg)
+      && !NULLPTR_TYPE_P (TREE_TYPE (arg)))
+    {
+      warning (OPT_Wzero_as_null_pointer_constant,
+              "zero as null pointer constant");
+      return nullptr_node;
+    }
+
   /* [dcl.fct.default]
 
      Local variables shall not be used in default argument
index d25b4d9..498218a 100644 (file)
@@ -1,3 +1,8 @@
+2012-03-29  Paolo Carlini  <paolo.carlini@oracle.com>
+
+       PR c++/52718
+       * g++.dg/warn/Wzero-as-null-pointer-constant-5.C: New.
+
 2012-03-29  Jason Merrill  <jason@redhat.com>
 
        PR c++/52685
diff --git a/gcc/testsuite/g++.dg/warn/Wzero-as-null-pointer-constant-5.C b/gcc/testsuite/g++.dg/warn/Wzero-as-null-pointer-constant-5.C
new file mode 100644 (file)
index 0000000..185d2b5
--- /dev/null
@@ -0,0 +1,20 @@
+// PR c++/52718
+// { dg-options "-Wzero-as-null-pointer-constant" }
+
+struct foo
+{
+  foo(void* a = 0) {};      // { dg-warning "zero as null pointer" }
+};
+
+void* fun(void* a = 0) {};  // { dg-warning "zero as null pointer" }
+
+struct bar: foo
+{
+  bar() {};
+};
+
+struct baz
+{
+  baz(const foo& f1 = foo(),
+      void* f2 = fun()) {};
+};