/* Change flag_abi_version to be the actual current ABI level, for the
benefit of c_cpp_builtins, and to make comparison simpler. */
- const int latest_abi_version = 19;
+ const int latest_abi_version = 20;
/* Generate compatibility aliases for ABI v13 (8.2) by default. */
const int abi_compat_default = 13;
; Default in G++ 13.
;
; 19: Emits ABI tags if needed in structured binding mangled names.
-; Ignores cv-quals on [[no_unique_object]] members.
+; Ignores cv-quals on [[no_unique_address]] members.
; Mangles constraints on function templates.
; Default in G++ 14.
;
+; 20: Fix mangling of lambdas in static data member initializers.
+; Default in G++ 15.
+;
; Additional positive integers will be assigned as new versions of
; the ABI become the default version of the ABI.
fabi-version=
tree, bool, tree, tree);
extern tree grokbitfield (const cp_declarator *, cp_decl_specifier_seq *,
tree, tree, tree);
+extern tree start_initialized_static_member (const cp_declarator *,
+ cp_decl_specifier_seq *, tree);
+extern void finish_initialized_static_member (tree, tree, tree);
extern tree splice_template_attributes (tree *, tree);
extern bool any_dependent_type_attributes_p (tree);
extern tree cp_reconstruct_complex_type (tree, tree);
return NULL_TREE;
}
+/* Like grokfield, but just for the initial grok of an initialized static
+ member. Used to be able to push the new decl before parsing the
+ initialiser. */
+
+tree
+start_initialized_static_member (const cp_declarator *declarator,
+ cp_decl_specifier_seq *declspecs,
+ tree attrlist)
+{
+ tree value = grokdeclarator (declarator, declspecs, FIELD, SD_INITIALIZED,
+ &attrlist);
+ if (!value || error_operand_p (value))
+ return error_mark_node;
+ if (TREE_CODE (value) == TYPE_DECL)
+ {
+ error_at (declarator->init_loc,
+ "typedef %qD is initialized (use %qs instead)",
+ value, "decltype");
+ return error_mark_node;
+ }
+ else if (TREE_CODE (value) == FUNCTION_DECL)
+ {
+ if (TREE_CODE (TREE_TYPE (value)) == METHOD_TYPE)
+ error_at (declarator->init_loc,
+ "invalid initializer for member function %qD",
+ value);
+ else if (TREE_CODE (TREE_TYPE (value)) == FUNCTION_TYPE)
+ error_at (declarator->init_loc,
+ "initializer specified for static member function %qD",
+ value);
+ else
+ gcc_unreachable ();
+ return error_mark_node;
+ }
+ else if (TREE_CODE (value) == FIELD_DECL)
+ {
+ /* NSDM marked 'static', grokdeclarator has already errored. */
+ gcc_checking_assert (seen_error ());
+ return error_mark_node;
+ }
+ gcc_checking_assert (VAR_P (value));
+
+ DECL_CONTEXT (value) = current_class_type;
+ if (processing_template_decl)
+ {
+ value = push_template_decl (value);
+ if (error_operand_p (value))
+ return error_mark_node;
+ }
+
+ if (attrlist)
+ cplus_decl_attributes (&value, attrlist, 0);
+
+ finish_member_declaration (value);
+ DECL_INITIALIZED_IN_CLASS_P (value) = true;
+
+ return value;
+}
+
+/* Finish a declaration prepared with start_initialized_static_member. */
+
+void
+finish_initialized_static_member (tree decl, tree init, tree asmspec)
+{
+ if (decl == error_mark_node)
+ return;
+ gcc_checking_assert (VAR_P (decl));
+
+ int flags;
+ if (init && DIRECT_LIST_INIT_P (init))
+ flags = LOOKUP_NORMAL;
+ else
+ flags = LOOKUP_IMPLICIT;
+ finish_static_data_member_decl (decl, init, /*init_const_expr_p=*/true,
+ asmspec, flags);
+}
+
/* Like `grokfield', but for bitfields.
WIDTH is the width of the bitfield, a constant expression.
The other parameters are as for grokfield. */
#include "gimplify.h"
#include "target.h"
#include "decl.h"
+#include "flags.h"
/* Constructor for a lambda expression. */
void
record_lambda_scope (tree lambda)
{
- LAMBDA_EXPR_EXTRA_SCOPE (lambda) = lambda_scope.scope;
- if (lambda_scope.scope)
+ tree closure = LAMBDA_EXPR_CLOSURE (lambda);
+ gcc_checking_assert (closure);
+
+ /* 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))
{
- tree closure = LAMBDA_EXPR_CLOSURE (lambda);
- gcc_checking_assert (closure);
- maybe_key_decl (lambda_scope.scope, TYPE_NAME (closure));
+ if (!abi_version_at_least (20))
+ scope = NULL_TREE;
+ if (warn_abi && abi_version_crosses (20) && !processing_template_decl)
+ {
+ if (abi_version_at_least (20))
+ warning_at (location_of (closure), OPT_Wabi,
+ "the mangled name of %qT changed in "
+ "%<-fabi-version=20%> (GCC 15.1)", closure);
+ else
+ warning_at (location_of (closure), OPT_Wabi,
+ "the mangled name of %qT changes in "
+ "%<-fabi-version=20%> (GCC 15.1)", closure);
+ }
}
+
+ LAMBDA_EXPR_EXTRA_SCOPE (lambda) = scope;
+ if (scope)
+ maybe_key_decl (scope, TYPE_NAME (closure));
}
// Compare lambda template heads TMPL_A and TMPL_B, used for both
tree first_attribute;
tree initializer;
bool named_bitfld = false;
+ bool decl_was_initialized_p = false;
/* Peek at the next token. */
token = cp_lexer_peek_token (parser->lexer);
pure-specifier. It is not correct to parse the
initializer before registering the member declaration
since the member declaration should be in scope while
- its initializer is processed. However, the rest of the
- front end does not yet provide an interface that allows
- us to handle this correctly. */
+ its initializer is processed. As such we might build
+ decl pre-emptively. */
if (cp_lexer_next_token_is (parser->lexer, CPP_EQ))
{
/* In [class.mem]:
initializer = cp_parser_pure_specifier (parser);
else if (decl_specifiers.storage_class != sc_static)
initializer = cp_parser_save_nsdmi (parser);
- else if (cxx_dialect >= cxx11)
+ else
{
- /* Don't require a constant rvalue in C++11, since we
- might want a reference constant. We'll enforce
- constancy later. */
- cp_lexer_consume_token (parser->lexer);
- /* Parse the initializer. */
- initializer = cp_parser_initializer_clause (parser);
+ decl = start_initialized_static_member (declarator,
+ &decl_specifiers,
+ attributes);
+ start_lambda_scope (decl);
+
+ if (cxx_dialect >= cxx11)
+ {
+ /* Don't require a constant rvalue in C++11, since we
+ might want a reference constant. We'll enforce
+ constancy later. */
+ cp_lexer_consume_token (parser->lexer);
+ /* Parse the initializer. */
+ initializer = cp_parser_initializer_clause (parser);
+ }
+ else
+ /* Parse the initializer. */
+ initializer = cp_parser_constant_initializer (parser);
+
+ finish_lambda_scope ();
+ finish_initialized_static_member (decl, initializer,
+ asm_specification);
+ decl_was_initialized_p = true;
}
- else
- /* Parse the initializer. */
- initializer = cp_parser_constant_initializer (parser);
}
else if (cp_lexer_next_token_is (parser->lexer, CPP_OPEN_BRACE)
&& !function_declarator_p (declarator))
if (decl_specifiers.storage_class != sc_static)
initializer = cp_parser_save_nsdmi (parser);
else
- initializer = cp_parser_initializer (parser);
+ {
+ decl = start_initialized_static_member (declarator,
+ &decl_specifiers,
+ attributes);
+ start_lambda_scope (decl);
+ initializer = cp_parser_initializer (parser);
+ finish_lambda_scope ();
+ finish_initialized_static_member (decl, initializer,
+ asm_specification);
+ decl_was_initialized_p = true;
+ }
}
/* Detect invalid bit-field cases such as
declarator->id_loc = token->location;
/* Create the declaration. */
- decl = grokfield (declarator, &decl_specifiers,
- initializer, /*init_const_expr_p=*/true,
- asm_specification, attributes);
-
- if (parser->fully_implicit_function_template_p)
+ if (!decl_was_initialized_p)
{
- if (friend_p)
- finish_fully_implicit_template (parser, 0);
- else
- decl = finish_fully_implicit_template (parser, decl);
+ decl = grokfield (declarator, &decl_specifiers,
+ initializer, /*init_const_expr_p=*/true,
+ asm_specification, attributes);
+
+ if (parser->fully_implicit_function_template_p)
+ {
+ if (friend_p)
+ finish_fully_implicit_template (parser, 0);
+ else
+ decl = finish_fully_implicit_template (parser, decl);
+ }
}
}
assume_semicolon = true;
}
- if (decl)
+ if (decl && !decl_was_initialized_p)
{
/* Add DECL to the list of members. */
if (!friend_p
Version 19, which first appeard in G++ 14, fixes manglings of structured
bindings to include ABI tags.
+Version 20, which first appeared in G++ 15, fixes manglings of lambdas
+in static data member initializers.
+
See also @option{-Wabi}.
@opindex fabi-compat-version
--- /dev/null
+// { dg-do compile { target c++17 } }
+// { dg-options -fabi-version=19 }
+
+#include "lambda-ctx2.h"
+
+// A and B demangle incorrectly due to static data members missing a lambda scope
+// { dg-final { scan-assembler {_ZNK1AUlvE_clEv:} } }
+// { dg-final { scan-assembler {_ZNK1BIiEUlvE2_clEv:} } }
+// { dg-final { scan-assembler {_ZNK1BIiEUlvE3_clEv:} } }
+// { dg-final { scan-assembler {_ZNK1CIiE1xMUlvE_clEv:} } }
--- /dev/null
+// { dg-do compile { target c++17 } }
+// { dg-options "-fabi-version=20 -Wabi=19" }
+
+#include "lambda-ctx2.h"
+
+// { 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} }
--- /dev/null
+// { dg-do compile { target c++17 } }
+// { dg-options -fabi-version=20 }
+
+#include "lambda-ctx2.h"
+
+// These correctly associate lambdas in A::x and B::x.
+// { dg-final { scan-assembler {_ZNK1A1xMUlvE_clEv:} } }
+// { dg-final { scan-assembler {_ZNK1BIiE1xMUlvE_clEv:} } }
+// { dg-final { scan-assembler {_ZNK1BIiE1xMUlvE0_clEv:} } }
+// { dg-final { scan-assembler {_ZNK1CIiE1xMUlvE_clEv:} } }
--- /dev/null
+// PR c++/107741
+
+void side_effect();
+
+struct A {
+ static constexpr auto x = []{ return 1; };
+};
+
+template <typename>
+struct B {
+ static inline auto x = (side_effect(), []{ return 2; }(), []{ return 3; }());
+};
+
+template <typename>
+struct C {
+ static int x;
+};
+
+template <typename T>
+int C<T>::x = (side_effect(), []{ return 4; }());
+
+template int C<int>::x;
+
+int f() {
+ A::x();
+ return B<int>::x;
+}
// This testcase will need to be kept in sync with c_common_post_options.
// { dg-options "-fabi-version=0" }
-#if __GXX_ABI_VERSION != 1019
+#if __GXX_ABI_VERSION != 1020
#error "Incorrect value of __GXX_ABI_VERSION"
#endif
}
// { dg-final { scan-assembler "_ZNK3varMUlvE_clEv:" } }
-// { dg-final { scan-assembler "_ZNK3Foo3barMUlvE_clEv:" { xfail *-*-* } } }
-// { dg-final { scan-assembler-not "_ZNK3FooUlvE_clEv:" { xfail *-*-* } } }
+// { dg-final { scan-assembler "_ZNK3Foo3barMUlvE_clEv:" } }
+// { dg-final { scan-assembler-not "_ZNK3FooUlvE_clEv:" } }
--- /dev/null
+// { dg-do compile { target c++11 } }
+
+struct S {
+ static constexpr const void* x = &x;
+};
struct A
{
- static const int i = i; // { dg-error "not declared" }
+ static const int i = j; // { dg-error "not declared" }
int x[i]; // { dg-error "11:size of array .x. is not an integral constant-expression" }
};