Commit 55388afd by Jason Merrill Committed by Jason Merrill

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
parent c82e0b3b
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
......
......@@ -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
......
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
......
......@@ -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 {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment