]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR c++/42415 (Bad assembly generated for constructor call)
authorJason Merrill <jason@redhat.com>
Fri, 18 Dec 2009 16:12:50 +0000 (11:12 -0500)
committerJason Merrill <jason@gcc.gnu.org>
Fri, 18 Dec 2009 16:12:50 +0000 (11:12 -0500)
PR c++/42415
* call.c (build_new_method_call): Complain about calling the
constructor directly.

From-SVN: r155347

gcc/cp/ChangeLog
gcc/cp/call.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/tc1/dr147.C

index 1b7411b835eb3e046172d5ed8d146fc8f5ccc10b..4109c72cd71eaa05ef04931a68d4e2d6ec3bf54b 100644 (file)
@@ -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
index 0ed338301c5f550e0f80ef44ae6fd0bbae22d258..67f446555186f096f9a1c8de095b6986844e1d63 100644 (file)
@@ -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
index 7e55a57ba4851a6e4323a8a1b1cbea5963bfb7a0..af4e2ac87538b0d6da44dd4391edfaea0dfe9d49 100644 (file)
@@ -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
index 9006be9e1802beaf4c524d4df42a8608ae191525..a29986b55598b2af200d62a2bdbc07925d4afa82 100644 (file)
@@ -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 {