diff options
author | Jason Merrill <jason@redhat.com> | 2009-12-18 11:12:50 -0500 |
---|---|---|
committer | Jason Merrill <jason@gcc.gnu.org> | 2009-12-18 11:12:50 -0500 |
commit | 55388afda91143f447140a0b65a8b8fcfad3951b (patch) | |
tree | 7981096816f0116a865495f8daba77c46c1ae142 /gcc | |
parent | c82e0b3b1b7794f9903ab0b82ecaeabcd0d3a565 (diff) | |
download | gcc-55388afda91143f447140a0b65a8b8fcfad3951b.zip gcc-55388afda91143f447140a0b65a8b8fcfad3951b.tar.gz gcc-55388afda91143f447140a0b65a8b8fcfad3951b.tar.bz2 |
re PR c++/42415 (Bad assembly generated for constructor call)
PR c++/42415
* call.c (build_new_method_call): Complain about calling the
constructor directly.
From-SVN: r155347
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/cp/ChangeLog | 6 | ||||
-rw-r--r-- | gcc/cp/call.c | 20 | ||||
-rw-r--r-- | gcc/testsuite/ChangeLog | 5 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/tc1/dr147.C | 9 |
4 files changed, 37 insertions, 3 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 1b7411b..4109c72 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,9 @@ +2009-12-18 Jason Merrill <jason@redhat.com> + + PR c++/42415 + * call.c (build_new_method_call): Complain about calling the + constructor directly. + 2009-12-18 Shujing Zhao <pearly.zhao@oracle.com> PR c++/31665 diff --git a/gcc/cp/call.c b/gcc/cp/call.c index 0ed3383..67f4465 100644 --- a/gcc/cp/call.c +++ b/gcc/cp/call.c @@ -6239,6 +6239,25 @@ build_new_method_call (tree instance, tree fns, VEC(tree,gc) **args, make_args_non_dependent (*args); } + user_args = args == NULL ? NULL : *args; + /* Under DR 147 A::A() is an invalid constructor call, + not a functional cast. */ + if (DECL_MAYBE_IN_CHARGE_CONSTRUCTOR_P (fn)) + { + if (! (complain & tf_error)) + return error_mark_node; + + permerror (input_location, + "cannot call constructor %<%T::%D%> directly", + basetype, name); + inform (input_location, "for a function-style cast, remove the " + "redundant %<::%D%>", name); + call = build_functional_cast (basetype, build_tree_list_vec (user_args), + complain); + release_tree_vector (user_args); + return call; + } + /* Figure out whether to skip the first argument for the error message we will display to users if an error occurs. We don't want to display any compiler-generated arguments. The "this" @@ -6246,7 +6265,6 @@ build_new_method_call (tree instance, tree fns, VEC(tree,gc) **args, pointer if this is a call to a base-class constructor or destructor. */ skip_first_for_error = false; - user_args = args == NULL ? NULL : *args; if (IDENTIFIER_CTOR_OR_DTOR_P (name)) { /* Callers should explicitly indicate whether they want to construct diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 7e55a57..af4e2ac 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2009-12-18 Jason Merrill <jason@redhat.com> + + PR c++/42415 + * g++.dg/tc1/dr147.C: Add test. + 2009-12-18 Shujing Zhao <pearly.zhao@oracle.com> * g++.old-deja/g++.brendan/misc6.C: Make expected dg-error strings diff --git a/gcc/testsuite/g++.dg/tc1/dr147.C b/gcc/testsuite/g++.dg/tc1/dr147.C index 9006be9..a29986b 100644 --- a/gcc/testsuite/g++.dg/tc1/dr147.C +++ b/gcc/testsuite/g++.dg/tc1/dr147.C @@ -4,7 +4,7 @@ namespace N1 { -struct A { A(); }; +struct A { A(); void f(); }; struct B: public A { B(); }; A::A() { } @@ -13,10 +13,15 @@ B::B() { } B::A ba; A::A a; // { dg-error "constructor" "the injected-class-name can never be found through qualified lookup" } +void A::f() +{ + A::A(); // { dg-message "::A" "c++/42415" } +} + void f() { A::A a; // { dg-error "constructor" } -} // { dg-error "" "" { target *-*-* } 18 } error cascade +} // { dg-error "" "" { target *-*-* } 23 } error cascade } namespace N2 { |