tree, tree, tree);
extern tree start_initialized_static_member (const cp_declarator *,
cp_decl_specifier_seq *, tree);
+extern bool is_static_data_member_initialized_in_class (tree decl);
extern void finish_initialized_static_member (tree, tree, tree);
extern tree splice_template_attributes (tree *, tree);
extern bool any_dependent_type_attributes_p (tree);
gcc_checking_assert (VAR_P (value));
DECL_CONTEXT (value) = current_class_type;
+ DECL_INITIALIZED_IN_CLASS_P (value) = true;
+
if (processing_template_decl)
{
value = push_template_decl (value);
if (attrlist)
cplus_decl_attributes (&value, attrlist, 0);
- finish_member_declaration (value);
- DECL_INITIALIZED_IN_CLASS_P (value) = true;
+ /* When defining a template we need to register the TEMPLATE_DECL. */
+ tree maybe_template = value;
+ if (template_parm_scope_p ())
+ {
+ if (!DECL_TEMPLATE_SPECIALIZATION (value))
+ maybe_template = DECL_TI_TEMPLATE (value);
+ else
+ maybe_template = NULL_TREE;
+ }
+ if (maybe_template)
+ finish_member_declaration (maybe_template);
return value;
}
+/* Whether DECL is a static data member initialized at the point
+ of declaration within its class. */
+
+bool
+is_static_data_member_initialized_in_class (tree decl)
+{
+ if (!decl || decl == error_mark_node)
+ return false;
+
+ tree inner = STRIP_TEMPLATE (decl);
+ return (inner
+ && VAR_P (inner)
+ && DECL_CLASS_SCOPE_P (inner)
+ && DECL_INITIALIZED_IN_CLASS_P (inner));
+}
+
/* Finish a declaration prepared with start_initialized_static_member. */
void
{
if (decl == error_mark_node)
return;
- gcc_checking_assert (VAR_P (decl));
+ gcc_checking_assert (is_static_data_member_initialized_in_class (decl));
int flags;
if (init && DIRECT_LIST_INIT_P (init))
/* Before ABI v20, lambdas in static data member initializers did not
get a dedicated lambda scope. */
tree scope = lambda_scope.scope;
- if (scope
- && VAR_P (scope)
- && DECL_CLASS_SCOPE_P (scope)
- && DECL_INITIALIZED_IN_CLASS_P (scope))
+ if (is_static_data_member_initialized_in_class (scope))
{
if (!abi_version_at_least (20))
scope = NULL_TREE;
/* Enter the newly declared entry in the symbol table. If we're
processing a declaration in a class-specifier, we wait until
- after processing the initializer. */
- if (!member_p)
+ after processing the initializer, except for static data members
+ initialized here. */
+ if (member_p)
+ {
+ if (scope)
+ /* Enter the SCOPE. That way unqualified names appearing in the
+ initializer will be looked up in SCOPE. */
+ pushed_scope = push_scope (scope);
+
+ if (is_initialized
+ && decl_specifiers->storage_class == sc_static
+ && !function_declarator_p (declarator))
+ {
+ tree all_attrs = attr_chainon (attributes, prefix_attributes);
+ decl = start_initialized_static_member (declarator,
+ decl_specifiers,
+ all_attrs);
+ }
+ }
+ else
{
if (parser->in_unbraced_linkage_specification_p)
decl_specifiers->storage_class = sc_extern;
&& DECL_SOURCE_LOCATION (decl) == input_location)
DECL_SOURCE_LOCATION (decl) = declarator->id_loc;
}
- else if (scope)
- /* Enter the SCOPE. That way unqualified names appearing in the
- initializer will be looked up in SCOPE. */
- pushed_scope = push_scope (scope);
/* Perform deferred access control checks, now that we know in which
SCOPE the declared entity resides. */
bool has_lambda_scope = false;
if (decl != error_mark_node
- && !member_p
+ && decl
&& (processing_template_decl || DECL_NAMESPACE_SCOPE_P (decl)))
has_lambda_scope = true;
pop_scope (pushed_scope);
pushed_scope = NULL_TREE;
}
- decl = grokfield (declarator, decl_specifiers,
- initializer, !is_non_constant_init,
- /*asmspec=*/NULL_TREE,
- attr_chainon (attributes, prefix_attributes));
+ if (decl)
+ finish_initialized_static_member (decl, initializer,
+ /*asmspec=*/NULL_TREE);
+ else
+ decl = grokfield (declarator, decl_specifiers,
+ initializer, !is_non_constant_init,
+ /*asmspec=*/NULL_TREE,
+ attr_chainon (attributes, prefix_attributes));
if (decl && TREE_CODE (decl) == FUNCTION_DECL)
cp_parser_save_default_args (parser, decl);
cp_finalize_omp_declare_simd (parser, decl);
}
/* Register member declarations. */
- if (member_p && !friend_p && decl && !DECL_CLASS_TEMPLATE_P (decl))
+ if (member_p && !friend_p && decl && !DECL_CLASS_TEMPLATE_P (decl)
+ /* But this is not needed for initialised static members, that were
+ registered in start_initialized_static_member to be able to be used
+ in their own definition. */
+ && !is_static_data_member_initialized_in_class (decl))
finish_member_declaration (decl);
/* If DECL is a function template, we must return to parse it later.
(Even though there is no definition, there might be default
// { dg-final { scan-assembler {_ZNK1BIiEUlvE2_clEv:} } }
// { dg-final { scan-assembler {_ZNK1BIiEUlvE3_clEv:} } }
// { dg-final { scan-assembler {_ZNK1CIiE1xMUlvE_clEv:} } }
+// { dg-final { scan-assembler {_ZNK1DUlvE7_clEv:} } }
+// { dg-final { scan-assembler {_ZNK1EIiEUlvE8_clEv:} } }
+// { dg-final { scan-assembler {_ZNK1EIiEUlvE9_clEv:} } }
// { dg-regexp {[^\n]*lambda-ctx2.h:[:0-9]* warning: the mangled name of .A::<lambda>.[^\n]*\n} }
// { dg-regexp {[^\n]*lambda-ctx2.h:[:0-9]* warning: the mangled name of .B<int>::<lambda>.[^\n]*\n} }
// { dg-regexp {[^\n]*lambda-ctx2.h:[:0-9]* warning: the mangled name of .B<int>::<lambda>.[^\n]*\n} }
+// { dg-regexp {[^\n]*lambda-ctx2.h:[:0-9]* warning: the mangled name of .D::<lambda>.[^\n]*\n} }
+// { dg-regexp {[^\n]*lambda-ctx2.h:[:0-9]* warning: the mangled name of .E<int>::<lambda>.[^\n]*\n} }
+// { dg-regexp {[^\n]*lambda-ctx2.h:[:0-9]* warning: the mangled name of .E<int>::<lambda>.[^\n]*\n} }
// { dg-final { scan-assembler {_ZNK1BIiE1xMUlvE_clEv:} } }
// { dg-final { scan-assembler {_ZNK1BIiE1xMUlvE0_clEv:} } }
// { dg-final { scan-assembler {_ZNK1CIiE1xMUlvE_clEv:} } }
+// { dg-final { scan-assembler {_ZNK1D1xIiEUlvE_clEv:} } }
+// { dg-final { scan-assembler {_ZNK1EIiE1xIiEUlvE_clEv:} } }
+// { dg-final { scan-assembler {_ZNK1EIiE1xIiEUlvE0_clEv:} } }
A::x();
return B<int>::x;
}
+
+struct D {
+ template <typename>
+ static constexpr auto x = []{ return 5; };
+};
+
+template <typename>
+struct E {
+ template <typename>
+ static inline auto x = (side_effect(), []{ return 6; }(), []{ return 7; }());
+};
+
+int g() {
+ D::x<int>();
+ return E<int>::x<int>;
+}
// { dg-do compile { target c++11 } }
+// { dg-options "-pedantic" }
struct S {
static constexpr const void* x = &x;
+
+ template <typename> static inline const void* y = &y<int>;
+ // { dg-warning "variable templates only available with" "" { target c++11_down } .-1 }
+ // { dg-warning "inline variables are only available with" "" { target c++14_down } .-2 }
};