diff options
author | jason <jason@138bc75d-0d04-0410-961f-82ee72b054a4> | 2012-02-14 08:39:51 +0000 |
---|---|---|
committer | jason <jason@138bc75d-0d04-0410-961f-82ee72b054a4> | 2012-02-14 08:39:51 +0000 |
commit | ed30b6cc07fda843d3f2f6654f9f570edda33630 (patch) | |
tree | 9ca4bca98238648f7e0572eaf4f22cb388381a15 /gcc | |
parent | f4858af8ace52c7400e47d171319f61cfae61105 (diff) | |
download | gcc-ed30b6cc07fda843d3f2f6654f9f570edda33630.tar.gz |
PR c++/39055
* decl.c (local_variable_p_walkfn): Don't check DECL_ARTIFICIAL.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@184199 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/cp/ChangeLog | 5 | ||||
-rw-r--r-- | gcc/cp/decl.c | 10 | ||||
-rw-r--r-- | gcc/testsuite/ChangeLog | 5 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/overload/defarg5.C | 7 |
4 files changed, 24 insertions, 3 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 668066831ec..c20077c6db0 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,8 @@ +2012-02-14 Jason Merrill <jason@redhat.com> + + PR c++/39055 + * decl.c (local_variable_p_walkfn): Don't check DECL_ARTIFICIAL. + 2012-02-14 Jakub Jelinek <jakub@redhat.com> PR c/52181 diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c index 8fcfbd5a215..f0ba1816384 100644 --- a/gcc/cp/decl.c +++ b/gcc/cp/decl.c @@ -10509,7 +10509,9 @@ static tree local_variable_p_walkfn (tree *tp, int *walk_subtrees, void *data ATTRIBUTE_UNUSED) { - if (local_variable_p (*tp) && !DECL_ARTIFICIAL (*tp)) + /* Check DECL_NAME to avoid including temporaries. We don't check + DECL_ARTIFICIAL because we do want to complain about 'this'. */ + if (local_variable_p (*tp) && DECL_NAME (*tp)) return *tp; else if (TYPE_P (*tp)) *walk_subtrees = 0; @@ -10517,7 +10519,6 @@ local_variable_p_walkfn (tree *tp, int *walk_subtrees, return NULL_TREE; } - /* Check that ARG, which is a default-argument expression for a parameter DECL, is valid. Returns ARG, or ERROR_MARK_NODE, if something goes wrong. DECL may also be a _TYPE node, rather than a @@ -10578,7 +10579,10 @@ check_default_argument (tree decl, tree arg) var = cp_walk_tree_without_duplicates (&arg, local_variable_p_walkfn, NULL); if (var) { - error ("default argument %qE uses local variable %qD", arg, var); + if (DECL_NAME (var) == this_identifier) + permerror (input_location, "default argument %qE uses %qD", arg, var); + else + error ("default argument %qE uses local variable %qD", arg, var); return error_mark_node; } diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index bd0b6386071..38d09e5d132 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2012-02-14 Jason Merrill <jason@redhat.com> + + PR c++/39055 + * g++.dg/overload/defarg5.C: New. + 2012-02-14 Jakub Jelinek <jakub@redhat.com> PR c/52181 diff --git a/gcc/testsuite/g++.dg/overload/defarg5.C b/gcc/testsuite/g++.dg/overload/defarg5.C new file mode 100644 index 00000000000..06ea6bf4500 --- /dev/null +++ b/gcc/testsuite/g++.dg/overload/defarg5.C @@ -0,0 +1,7 @@ +// PR c++/39055 + +struct A +{ + int i; + A() { void foo(int=i); } // { dg-error "this" } +}; |