]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Fix PR c++/68948 (wrong code generation due to invalid constructor call)
authorppalka <ppalka@138bc75d-0d04-0410-961f-82ee72b054a4>
Fri, 5 Feb 2016 14:36:44 +0000 (14:36 +0000)
committerppalka <ppalka@138bc75d-0d04-0410-961f-82ee72b054a4>
Fri, 5 Feb 2016 14:36:44 +0000 (14:36 +0000)
gcc/cp/ChangeLog:

PR c++/68948
* pt.c (tsubst_baselink): Diagnose an invalid constructor call
if lookup_fnfields returns NULL_TREE and the name being looked
up has the form A::A.

gcc/testsuite/ChangeLog:

PR c++/68948
* g++.dg/template/pr68948.C: New test.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@233176 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/cp/ChangeLog
gcc/cp/pt.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/template/pr68948.C [new file with mode: 0644]

index 2b6362daf2f66b197c58e6b5fe86b41edb0cb51b..74e7cb17c0c7a53fdaf88f0136f645902ee563ab 100644 (file)
@@ -1,3 +1,10 @@
+2016-02-05  Patrick Palka  <ppalka@gcc.gnu.org>
+
+       PR c++/68948
+       * pt.c (tsubst_baselink): Diagnose an invalid constructor call
+       if lookup_fnfields returns NULL_TREE and the name being looked
+       up has the form A::A.
+
 2016-02-04  Patrick Palka  <ppalka@gcc.gnu.org>
 
        * constexpr.c (cxx_eval_binary_expression): Fold equality
index e7ce74c6c05239dabb55067488a353262e7ea4f1..76a6019a29e9fef35b57d65e1ec316aba42f1be5 100644 (file)
@@ -13583,7 +13583,15 @@ tsubst_baselink (tree baselink, tree object_type,
       name = mangle_conv_op_name_for_type (optype);
     baselink = lookup_fnfields (qualifying_scope, name, /*protect=*/1);
     if (!baselink)
-      return error_mark_node;
+      {
+       if (constructor_name_p (name, qualifying_scope))
+         {
+           if (complain & tf_error)
+             error ("cannot call constructor %<%T::%D%> directly",
+                    qualifying_scope, name);
+         }
+       return error_mark_node;
+      }
 
     /* If lookup found a single function, mark it as used at this
        point.  (If it lookup found multiple functions the one selected
index 1288df75ad68c5e4e399f682badd87bb7f9a5cc1..344b7d34f3842ed6b217c0cab22559c90495af5c 100644 (file)
@@ -1,3 +1,8 @@
+2016-02-05  Patrick Palka  <ppalka@gcc.gnu.org>
+
+       PR c++/68948
+       * g++.dg/template/pr68948.C: New test.
+
 2016-02-05  Dominik Vogt  <vogt@linux.vnet.ibm.com>
 
        * gcc.dg/tree-ssa/ssa-dom-cse-2.c: Remove -march=z13 for s390
diff --git a/gcc/testsuite/g++.dg/template/pr68948.C b/gcc/testsuite/g++.dg/template/pr68948.C
new file mode 100644 (file)
index 0000000..3cb6844
--- /dev/null
@@ -0,0 +1,41 @@
+// PR c++/68948
+
+struct B { B (); B (int); };
+
+struct Time : B { };
+
+/* Here, A and B are unrelated types.  */
+
+template <typename>
+struct A
+{
+  void TestBody ()
+  {
+    B::B (); // { dg-error "cannot call constructor .B::B." }
+    B::B::B (); // { dg-error "cannot call constructor .B::B." }
+    B::B (0); // { dg-error "cannot call constructor .B::B." }
+  }
+};
+
+/* Here, C is (indirectly) derived from B.  */
+
+template <typename g>
+struct C : Time
+{
+  void TestBody ()
+  {
+    B::B (); // { dg-error "cannot call constructor .B::B." }
+    B::B::B (); // { dg-error "cannot call constructor .B::B." }
+    B::B (0); // { dg-error "cannot call constructor .B::B." }
+    Time::B (0);
+  }
+};
+
+int
+main (void)
+{
+  A<int> a;
+  C<int> c;
+  a.TestBody ();
+  c.TestBody ();
+}