From: paolo Date: Thu, 29 Mar 2012 22:45:46 +0000 (+0000) Subject: /cp X-Git-Tag: upstream/4.9.2~13511 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=c55e1e56df2feb8fbb93599a724e6270673e386f;p=platform%2Fupstream%2Flinaro-gcc.git /cp 2012-03-29 Paolo Carlini 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 PR c++/52718 * g++.dg/warn/Wzero-as-null-pointer-constant-5.C: New. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@185983 138bc75d-0d04-0410-961f-82ee72b054a4 --- diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index af7fa2d..7e4e549 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,9 @@ +2012-03-29 Paolo Carlini + + 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 PR c++/52685 diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c index 8c5fda6..a89523d 100644 --- a/gcc/cp/decl.c +++ b/gcc/cp/decl.c @@ -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 diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index d25b4d9..498218a 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2012-03-29 Paolo Carlini + + PR c++/52718 + * g++.dg/warn/Wzero-as-null-pointer-constant-5.C: New. + 2012-03-29 Jason Merrill 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 index 0000000..185d2b5 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wzero-as-null-pointer-constant-5.C @@ -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()) {}; +};