if (TYPE_P (context) && COMPLETE_TYPE_P (complete_type (context)))
{
+ bool this_tmpl = (processing_template_decl
+ > template_class_depth (context));
if (VAR_P (decl))
{
tree field = lookup_field (context, DECL_NAME (decl), 0, false);
- if (field == NULL_TREE || !VAR_P (field))
- error ("%q#D is not a static member of %q#T", decl, context);
+ if (field == NULL_TREE
+ || !(VAR_P (field) || variable_template_p (field)))
+ error ("%q+#D is not a static data member of %q#T", decl, context);
else
{
+ if (variable_template_p (field))
+ {
+ if (!this_tmpl)
+ {
+ error_at (DECL_SOURCE_LOCATION (decl),
+ "non-member-template declaration of %qD", decl);
+ inform (DECL_SOURCE_LOCATION (field), "does not match "
+ "member template declaration here");
+ return error_mark_node;
+ }
+ 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)
{
if (!same_type_p (DECL_CONTEXT (field), context))
else
{
tree field = check_classfn (context, decl,
- (processing_template_decl
- > template_class_depth (context))
+ this_tmpl
? current_template_parms
: NULL_TREE);
if (field && field != error_mark_node
&& DECL_CONTEXT (value) != current_class_type)
return value;
+ /* Need to set this before push_template_decl. */
+ if (TREE_CODE (value) == VAR_DECL)
+ DECL_CONTEXT (value) = current_class_type;
+
if (processing_template_decl && VAR_OR_FUNCTION_DECL_P (value))
{
value = push_template_decl (value);
same_type_p, because DECL_CONTEXT is always
canonical... */
if (ctx == DECL_CONTEXT (t)
- && (TREE_CODE (t) != TYPE_DECL
- /* ... unless T is a member template; in which
- case our caller can be willing to create a
- specialization of that template represented
- by T. */
- || !(DECL_TI_TEMPLATE (t)
- && DECL_MEMBER_TEMPLATE_P (DECL_TI_TEMPLATE (t)))))
+ /* ... unless T is a member template; in which
+ case our caller can be willing to create a
+ specialization of that template represented
+ by T. */
+ && !(DECL_TI_TEMPLATE (t)
+ && DECL_MEMBER_TEMPLATE_P (DECL_TI_TEMPLATE (t))))
spec = t;
}