===================================================================
@@ -4926,6 +4926,18 @@
return TREE_TYPE (type_of_this_parm (fntype));
}
+/* True if T designates a variable template declaration. */
+inline bool
+variable_template_p (tree t)
+{
+ if (TREE_CODE (t) != TEMPLATE_DECL
+ || !(DECL_NAMESPACE_SCOPE_P (t) || DECL_MEMBER_TEMPLATE_P (t)))
+ return false;
+ if (tree r = DECL_TEMPLATE_RESULT (t))
+ return VAR_P (r);
+ return false;
+}
+
/* A parameter list indicating for a function with no parameters,
e.g "int f(void)". */
extern cp_parameter_declarator *no_parameters;
===================================================================
@@ -2270,9 +2270,11 @@
{
tree ctx = CP_DECL_CONTEXT (decl);
int wanted = num_template_headers_for_class (ctx);
- if (!TYPE_P (ctx) || !CLASSTYPE_TEMPLATE_INFO (ctx))
- permerror (DECL_SOURCE_LOCATION (decl),
- "%qD is not a static data member of a class template", decl);
+ if (!TYPE_P (ctx) || !CLASSTYPE_TEMPLATE_INFO (ctx)) {
+ if (cxx_dialect < cxx1y)
+ permerror (DECL_SOURCE_LOCATION (decl),
+ "%qD is not a static data member of a class template", decl);
+ }
else if (template_header_count > wanted)
{
pedwarn (DECL_SOURCE_LOCATION (decl), 0,
@@ -4616,6 +4618,10 @@
&& TYPE_DECL_ALIAS_P (decl))
/* alias-declaration */
gcc_assert (!DECL_ARTIFICIAL (decl));
+ else if (VAR_P (decl)) {
+ if (!DECL_DECLARED_CONSTEXPR_P (decl))
+ error ("template declaration of non-constexpr variable %qD", decl);
+ }
else
{
error ("template declaration of %q#D", decl);