]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Fix PR c++/69961 (invalid ctor call with dependent args)
authorPatrick Palka <ppalka@gcc.gnu.org>
Tue, 1 Mar 2016 01:24:44 +0000 (01:24 +0000)
committerPatrick Palka <ppalka@gcc.gnu.org>
Tue, 1 Mar 2016 01:24:44 +0000 (01:24 +0000)
gcc/cp/ChangeLog:

PR c++/68948
PR c++/69961
* pt.c (tsubst_baselink): Reinstate the check for an invalid
constructor call.

gcc/testsuite/ChangeLog:

PR c++/69961
* g++.dg/template/pr69961a.C: New test.
* g++.dg/template/pr69961b.C: New test.

From-SVN: r233838

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

index 49ca2f273fda63bf5c1d4ea05e7adda667f8c7ba..04e14268459818453b5732ba6f911ae2dfa49d22 100644 (file)
@@ -1,3 +1,10 @@
+2016-03-01  Patrick Palka  <ppalka@gcc.gnu.org>
+
+       PR c++/68948
+       PR c++/69961
+       * pt.c (tsubst_baselink): Reinstate the check for an invalid
+       constructor call.
+
 2016-02-28  Jason Merrill  <jason@redhat.com>
 
        PR c++/69995
index b5855a8d13ccf5e503ecf5c98a2f49907b1e62d3..b3681be9e43879785c4e45e1a2e9b31dba5c801b 100644 (file)
@@ -13622,7 +13622,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 50c4aa9e1f5a37041f02cc2ec41836af46b59512..38c738163681bd744abf1de0f1a7f5b715116845 100644 (file)
@@ -1,3 +1,9 @@
+2016-03-01  Patrick Palka  <ppalka@gcc.gnu.org>
+
+       PR c++/69961
+       * g++.dg/template/pr69961a.C: New test.
+       * g++.dg/template/pr69961b.C: New test.
+
 2016-02-29  David Malcolm  <dmalcolm@redhat.com>
 
        PR preprocessor/69985
diff --git a/gcc/testsuite/g++.dg/template/pr69961a.C b/gcc/testsuite/g++.dg/template/pr69961a.C
new file mode 100644 (file)
index 0000000..b0c5d41
--- /dev/null
@@ -0,0 +1,25 @@
+// PR c++/69961
+// { dg-do compile { target c++11 } }
+
+#include <string>
+
+using std::string;
+
+class Format {
+ public:
+  explicit Format(string formatted) {}
+  string buffer;
+};
+
+string StrCat(const string& a) {
+  return "";
+}
+
+template <typename... AV>
+Format Message(string msg, const AV&... args) {
+  return Format::Format(StrCat(msg, args...)); // { dg-error "cannot call constructor" }
+}
+
+int main(int, char**) {
+  Message("msg");
+}
diff --git a/gcc/testsuite/g++.dg/template/pr69961b.C b/gcc/testsuite/g++.dg/template/pr69961b.C
new file mode 100644 (file)
index 0000000..5fff1c9
--- /dev/null
@@ -0,0 +1,15 @@
+// PR c++/69961
+
+struct A { A (int); };
+
+template <typename T>
+void foo ()
+{
+  A::A ((T)0); // { dg-error "cannot call constructor .A::A. directly" }
+}
+
+void
+bar ()
+{
+  foo<int> ();
+}