+2014-09-10 Jason Merrill <jason@redhat.com>
+
+ PR c++/61659
+ * decl.c (grokfndecl): Don't set DECL_COMDAT on static inlines.
+ (duplicate_decls, start_decl): Likewise.
+ * pt.c (check_explicit_specialization): Likewise.
+ (push_template_decl_real): Or static templates.
+
2014-09-08 Jason Merrill <jason@redhat.com>
* typeck.c (build_class_member_access_expr): Move
olddecl);
SET_DECL_TEMPLATE_SPECIALIZATION (olddecl);
- DECL_COMDAT (newdecl) = DECL_DECLARED_INLINE_P (newdecl);
+ DECL_COMDAT (newdecl) = (TREE_PUBLIC (newdecl)
+ && DECL_DECLARED_INLINE_P (newdecl));
/* Don't propagate visibility from the template to the
specialization here. We'll do that in determine_visibility if
{
SET_DECL_TEMPLATE_SPECIALIZATION (decl);
if (TREE_CODE (decl) == FUNCTION_DECL)
- DECL_COMDAT (decl) = DECL_DECLARED_INLINE_P (decl);
+ DECL_COMDAT (decl) = (TREE_PUBLIC (decl)
+ && DECL_DECLARED_INLINE_P (decl));
else
DECL_COMDAT (decl) = false;
if (inlinep)
{
DECL_DECLARED_INLINE_P (decl) = 1;
- DECL_COMDAT (decl) = 1;
+ if (publicp)
+ DECL_COMDAT (decl) = 1;
}
if (inlinep & 2)
DECL_DECLARED_CONSTEXPR_P (decl) = true;
SET_DECL_IMPLICIT_INSTANTIATION (decl);
else if (TREE_CODE (decl) == FUNCTION_DECL)
/* A specialization is not necessarily COMDAT. */
- DECL_COMDAT (decl) = DECL_DECLARED_INLINE_P (decl);
+ DECL_COMDAT (decl) = (TREE_PUBLIC (decl)
+ && DECL_DECLARED_INLINE_P (decl));
else if (TREE_CODE (decl) == VAR_DECL)
DECL_COMDAT (decl) = false;
if (flag_implicit_templates
&& !is_friend
+ && TREE_PUBLIC (decl)
&& VAR_OR_FUNCTION_DECL_P (decl))
/* Set DECL_COMDAT on template instantiations; if we force
them to be emitted by explicit instantiation or -frepo,
--- /dev/null
+// { dg-options "-fno-weak" }
+// { dg-final { scan-assembler "local\[ \t\]*_ZZL1fvE1i" { target x86_64-*-*gnu } } }
+// { dg-final { scan-assembler "local\[ \t\]*_ZZ1gIiEvvE1i" { target x86_64-*-*gnu } } }
+
+static inline void f()
+{
+ static int i;
+ ++i;
+};
+
+template <class T> static void g()
+{
+ static int i;
+ ++i;
+}
+
+int main()
+{
+ f();
+ g<int>();
+}