@@ -5772,6 +5772,7 @@ extern tree cxx_maybe_build_cleanup (tr
/* in decl2.c */
extern void note_mangling_alias (tree, tree);
+extern void generate_mangling_aliases (void);
extern bool check_java_method (tree);
extern tree build_memfn_type (tree, tree, cp_cv_quals, cp_ref_qualifier);
extern tree build_pointer_ptrmemfn_type (tree);
@@ -4399,7 +4399,7 @@ note_mangling_alias (tree decl ATTRIBUTE
#endif
}
-static void
+void
generate_mangling_aliases ()
{
while (!vec_safe_is_empty (mangling_aliases))
@@ -270,7 +270,11 @@ maybe_thunk_body (tree fn, bool force)
}
else if (HAVE_COMDAT_GROUP)
{
+ /* Avoid creating mangling aliases if at_eof. */
+ int save_at_eof = at_eof;
+ at_eof = 0;
tree comdat_group = cdtor_comdat_group (fns[1], fns[0]);
+ at_eof = save_at_eof;
cgraph_node::get_create (fns[0])->set_comdat_group (comdat_group);
cgraph_node::get_create (fns[1])->add_to_same_comdat_group
(cgraph_node::get_create (fns[0]));
@@ -281,6 +285,9 @@ maybe_thunk_body (tree fn, bool force)
virtual, it goes into the same comdat group as well. */
cgraph_node::get_create (fns[2])->add_to_same_comdat_group
(symtab_node::get (fns[0]));
+ /* Emit them now that the thunks are same comdat group aliases. */
+ if (save_at_eof)
+ generate_mangling_aliases ();
TREE_PUBLIC (fn) = false;
DECL_EXTERNAL (fn) = false;
DECL_INTERFACE_KNOWN (fn) = true;
@@ -0,0 +1,21 @@
+// PR c++/67354
+// { dg-do compile { target c++11 } }
+// { dg-options "-fabi-version=5 -Os" }
+
+class A
+{
+};
+
+template <typename T>
+void
+foo ()
+{
+ T ();
+}
+
+struct B : virtual A
+{
+ template <typename...> B () {}
+};
+
+auto f = foo<B>;