2014-08-25 Jason Merrill <jason@redhat.com>
+ * pt.c (check_explicit_specialization): Don't complain about
+ non-template variable.
+ (template_for_substitution): Allow variable templates.
+ (check_template_variable): Fix logic for member var template.
+ * decl.c (start_decl): Don't complain about extra template header
+ here.
+
* decl.c (start_decl): Look through member variable template.
* pt.c (tsubst_decl) [VAR_DECL]: Handle member variable templates.
* decl2.c (grokfield): Set DECL_CONTEXT earlier on
}
field = DECL_TEMPLATE_RESULT (field);
}
- else if (this_tmpl)
- {
- error_at (DECL_SOURCE_LOCATION (decl),
- "member template declaration of %qD", decl);
- inform (DECL_SOURCE_LOCATION (field), "does not match "
- "non-member-template declaration here");
- return error_mark_node;
- }
if (DECL_CONTEXT (field) != context)
{
{
tree ctx = CP_DECL_CONTEXT (decl);
int wanted = num_template_headers_for_class (ctx);
- if (!TYPE_P (ctx) || !CLASSTYPE_TEMPLATE_INFO (ctx))
+ if (DECL_LANG_SPECIFIC (decl) && DECL_TEMPLATE_INFO (decl)
+ && PRIMARY_TEMPLATE_P (DECL_TI_TEMPLATE (decl)))
{
if (cxx_dialect < cxx14)
pedwarn (DECL_SOURCE_LOCATION (decl), 0,
bool warned = pedwarn (DECL_SOURCE_LOCATION (decl), 0,
"too many template headers for %D (should be %d)",
decl, wanted);
- if (warned && CLASSTYPE_TEMPLATE_SPECIALIZATION (ctx))
+ if (warned && CLASS_TYPE_P (ctx)
+ && CLASSTYPE_TEMPLATE_SPECIALIZATION (ctx))
inform (DECL_SOURCE_LOCATION (decl),
"members of an explicitly specialized class are defined "
"without a template header");
/* Fall through. */
case tsk_expl_spec:
if (VAR_P (decl) && TREE_CODE (declarator) != TEMPLATE_ID_EXPR)
- {
- // In cases like template<> constexpr bool v = true;
- error ("%qD is not a template variable", dname);
- break;
- }
+ /* In cases like template<> constexpr bool v = true;
+ We'll give an error in check_template_variable. */
+ break;
SET_DECL_TEMPLATE_SPECIALIZATION (decl);
if (ctype)
cannot restructure the loop to just keep going until we find
a template with a definition, since that might go too far if
a specialization was declared, but not defined. */
- gcc_assert (!VAR_P (decl)
- || DECL_IN_AGGR_P (DECL_TEMPLATE_RESULT (tmpl)));
/* Fetch the more general template. */
tmpl = DECL_TI_TEMPLATE (tmpl);