2014-11-21 Jason Merrill <jason@redhat.com>
+ PR c++/63942
+ * name-lookup.c (supplement_binding_1): Override a mangling alias.
+ * mangle.c (maybe_remove_implicit_alias): New.
+ (mangle_decl): Always avoid creating conflicting alias.
+ * cp-tree.h: Adjust.
+
PR c++/63849
* mangle.c (decl_mangling_context): Use template_type_parameter_p.
extern tree merge_exception_specifiers (tree, tree);
/* in mangle.c */
+extern bool maybe_remove_implicit_alias (tree);
extern void init_mangle (void);
extern void mangle_decl (tree);
extern const char *mangle_type_string (tree);
return targetm.mangle_decl_assembler_name (decl, id);
}
+/* If DECL is a mangling alias, remove it from the symbol table and return
+ true; otherwise return false. */
+
+bool
+maybe_remove_implicit_alias (tree decl)
+{
+ if (DECL_P (decl) && DECL_ARTIFICIAL (decl)
+ && DECL_IGNORED_P (decl)
+ && (TREE_CODE (decl) == FUNCTION_DECL
+ || (TREE_CODE (decl) == VAR_DECL
+ && TREE_STATIC (decl))))
+ {
+ symtab_node *n = symtab_node::get (decl);
+ if (n && n->cpp_implicit_alias)
+ {
+ n->remove();
+ return true;
+ }
+ }
+ return false;
+}
+
/* Create an identifier for the external mangled name of DECL. */
void
}
#ifdef ASM_OUTPUT_DEF
- if (flag_abi_compat_version != 0
- && IDENTIFIER_GLOBAL_VALUE (id2))
+ /* If there's a declaration already using this mangled name,
+ don't create a compatibility alias that conflicts. */
+ if (IDENTIFIER_GLOBAL_VALUE (id2))
return;
tree alias = make_alias_for (decl, id2);
region to refer only to the namespace to which it already
refers. */
ok = false;
+ else if (maybe_remove_implicit_alias (bval))
+ {
+ /* There was a mangling compatibility alias using this mangled name,
+ but now we have a real decl that wants to use it instead. */
+ binding->value = decl;
+ }
else
{
diagnose_name_conflict (decl, bval);
--- /dev/null
+// PR c++/63942
+// A mangling alias for the first constructor was conflicting with the second.
+// { dg-do compile { target c++11 } }
+// { dg-options "-fno-inline" }
+
+int i;
+template <class T> struct A
+{
+ A(const T&) { i = 42; }
+ A(const A&) { i = 36; }
+};
+
+typedef A<decltype(nullptr)> An;
+
+int main()
+{
+ An a (nullptr);
+ if (i != 42) __builtin_abort();
+ An a2 (a);
+ if (i != 36) __builtin_abort();
+}