@@ -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
new file mode 100644
@@ -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 (); // { dg-error "cannot call constructor" }
+ B::B (0); // { dg-error "cannot call constructor" }
+ }
+};
+
+/* 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 (); // { dg-error "cannot call constructor" }
+ B::B (0); // { dg-error "cannot call constructor" }
+ Time::B (0);
+ }
+};
+
+int
+main (void)
+{
+ A<int> a;
+ C<int> c;
+ a.TestBody ();
+ c.TestBody ();
+}