2011-11-10 Jason Merrill <jason@redhat.com>
+ PR c++/50372
+ * pt.c (convert_nontype_argument_function): Allow decls with
+ internal linkage in C++11.
+ (convert_nontype_argument): Likewise.
+
PR c++/50973
* decl2.c (mark_used): Defer synthesis of virtual functions.
* method.c (use_thunk): Make sure the target function has
{
tree fns = expr;
tree fn, fn_no_ptr;
+ linkage_kind linkage;
fn = instantiate_type (type, fns, tf_none);
if (fn == error_mark_node)
A template-argument for a non-type, non-template template-parameter
shall be one of:
[...]
- -- the address of an object or function with external linkage. */
- if (!DECL_EXTERNAL_LINKAGE_P (fn_no_ptr))
+ -- the address of an object or function with external [C++11: or
+ internal] linkage. */
+ linkage = decl_linkage (fn_no_ptr);
+ if (cxx_dialect >= cxx0x ? linkage == lk_none : linkage != lk_external)
{
- error ("%qE is not a valid template argument for type %qT "
- "because function %qD has not external linkage",
- expr, type, fn_no_ptr);
+ if (cxx_dialect >= cxx0x)
+ error ("%qE is not a valid template argument for type %qT "
+ "because %qD has no linkage",
+ expr, type, fn_no_ptr);
+ else
+ error ("%qE is not a valid template argument for type %qT "
+ "because %qD does not have external linkage",
+ expr, type, fn_no_ptr);
return NULL_TREE;
}
expr, type, decl);
return NULL_TREE;
}
- else if (!DECL_EXTERNAL_LINKAGE_P (decl))
+ else if (cxx_dialect < cxx0x && !DECL_EXTERNAL_LINKAGE_P (decl))
{
error ("%qE is not a valid template argument of type %qT "
"because %qD does not have external linkage",
expr, type, decl);
return NULL_TREE;
}
+ else if (cxx_dialect >= cxx0x && decl_linkage (decl) == lk_none)
+ {
+ error ("%qE is not a valid template argument of type %qT "
+ "because %qD has no linkage",
+ expr, type, decl);
+ return NULL_TREE;
+ }
}
expr = decay_conversion (expr);
static void fn2 () {}
};
call<&B1::fn1> ();
- call<&B2::fn2> (); // { dg-error "not external linkage|no matching" }
- // { dg-message "candidate" "candidate note" { target *-*-* } 29 }
+ call<&B2::fn2> (); // { dg-error "linkage|no matching" }
call<&fn3> ();
call<&B1::fn4> ();
- call<&fn5> (); // { dg-error "not external linkage|no matching" }
- // { dg-message "candidate" "candidate note" { target *-*-* } 33 }
+ call<&fn5> (); // { dg-error "linkage|no matching" "" { target c++98 } }
}
--- /dev/null
+// PR c++/50372
+// Test that a template instantiation has the same linkage as its argument.
+// { dg-final { scan-assembler "(weak|glob)\[^\n\]*_Z3fooIXadL_Z13external_funcvEEEvv" } }
+// { dg-final { scan-assembler-not "(weak|glob)\[^\n\]*_Z3fooIXadL_ZL11static_funcvEEEvv" } }
+
+template<void (*fptr)(void)>
+void foo() { }
+
+static void static_func() {}
+void external_func() { }
+
+void test()
+{
+#if __cplusplus > 199711L
+ foo<&static_func>();
+#endif
+ foo<&external_func>();
+}