===================================================================
@@ -0,0 +1,12 @@
+// PR c++/44039
+
+struct locale { };
+
+template<class charT>
+ void
+ foo()
+ { locale::locale(); } // // { dg-error "cannot call|function-style" }
+
+void
+bar()
+{ foo<char>(); }
===================================================================
@@ -10737,6 +10737,8 @@ tsubst_baselink (tree baselink, tree object_type,
if (IDENTIFIER_TYPENAME_P (name))
name = mangle_conv_op_name_for_type (optype);
baselink = lookup_fnfields (qualifying_scope, name, /*protect=*/1);
+ if (!baselink)
+ 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