Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 3 additions & 7 deletions src/attribute.c
Original file line number Diff line number Diff line change
Expand Up @@ -10818,18 +10818,15 @@ is_definition is TRUE if the new attribute (new_ap) appears on a definition.
*/
{
a_diag_list diag_list;
a_diagnostic_ptr dp;

if (is_definition) {
if (new_ap == NULL) {
/* If a previous declaration specified an alignment but the
definition does not, give an error. */
clear_diag_list(&diag_list);
dp = pos_start_error(ec_no_alignment_on_definition, def_pos);
more_info_diagnostic(ec_attribute_declared_here, &old_ap->position,
&diag_list);
add_more_info_list(dp, &diag_list);
end_diagnostic(dp);
error_with_notes(ec_no_alignment_on_definition, def_pos, &diag_list);
} else {
/* There may be multiple alignment attributes on both the prior
declaration as well as the current one. Look for the strictest
Expand All @@ -10854,11 +10851,10 @@ is_definition is TRUE if the new attribute (new_ap) appears on a definition.
equivalent values). */
if (old_align != new_align) {
clear_diag_list(&diag_list);
dp = pos_start_error(ec_align_not_equivalent, &new_ap->position);
more_info_diagnostic(ec_attribute_declared_here, &old_ap->position,
&diag_list);
add_more_info_list(dp, &diag_list);
end_diagnostic(dp);
error_with_notes(ec_align_not_equivalent, &new_ap->position,
&diag_list);
err = TRUE;
} /* if */
} /* if */
Expand Down
7 changes: 6 additions & 1 deletion src/c_gen_be.c
Original file line number Diff line number Diff line change
Expand Up @@ -4409,7 +4409,12 @@ the scope must be the file scope.
for (solhp = il_header.scope_orphaned_list_headers;
solhp != NULL;
solhp = solhp->next) {
if (ignore_routine_in_back_end(solhp->assoc_routine)) continue;
if (solhp->in_expansion_prototype ||
ignore_routine_in_back_end(solhp->assoc_routine)) {
/* In addition to routines ignored by the back end, expansion statement
prototype scopes do not contribute types to the generated code. */
continue;
} /* if */
for (type = solhp->orphaned_types;
type != NULL;
type = type->next) {
Expand Down
74 changes: 47 additions & 27 deletions src/class_decl.c
Original file line number Diff line number Diff line change
Expand Up @@ -2691,21 +2691,24 @@ created return NULL and:
/* The variable is not valid. err_code explains why. */
} else if (!lambda->has_capture_default) {
/* No capture default, so implicit captures are not allowed. However,
if the variable is constant-valued, the use of the constant value
does not require capture. */
a use of the constant value of a constant-valued variable does not
require capture. */
if (vp != NULL && vp->constant_valued && rvalue_only != NULL) {
*rvalue_only = TRUE;
} else {
err_code = (vp != NULL && vp->is_this_parameter) ?
ec_not_captured_this_in_lambda :
ec_not_captured_local_var_in_lambda;
} /* if */
} else if (rp->is_template_function && !rp->is_prototype_instantiation) {
} else if (rp->is_template_function && !rp->is_prototype_instantiation &&
!scope_stack_top().in_expansion_statement_body) {
/* We're attempting to capture during the real instantiation of a
generic lambda, but all captures should have been determined during
the prototype instantiation. A valid program can get here if there
is a capture default, but the variable is constant-valued and only
used as a prvalue. Otherwise, this is an error. */
the prototype instantiation (not in the prototype scan of an
expansion statement body, whose real lambdas are created by the
per-element rescans). A valid program can get here if there is a
capture default, but the variable is constant-valued and only used
as a prvalue. Otherwise, this is an error. */
if (vp != NULL) {
if (vp->constant_valued && rvalue_only != NULL) {
*rvalue_only = TRUE;
Expand Down Expand Up @@ -3059,11 +3062,12 @@ none.
void early_eh_spec_fixup(a_routine_ptr rp,
an_exception_specification_ptr esp)
/*
rp is a non-template member function with a pending fixup to scan the operand
of its noexcept specifier. Ordinarily, that would be scanned when the class
and its parent classes are completed, but a member declaration has triggered
the need for the exception specification to be determined earlier. Perform
the delayed scan of the noexcept operand now.
rp is a member function with a pending class fixup to scan the operand of its
noexcept specifier, represented by esp. It is either a non-template function
or an expansion-only prototype without a template declaration cache.
Ordinarily, the operand would be scanned when the class and its parent classes
are completed, but a member declaration requires the exception specification
to be determined earlier. Perform the delayed scan of the operand now.
*/
{
a_token_cache_ptr cache = esp->variant.token_cache;
Expand Down Expand Up @@ -4048,7 +4052,8 @@ nested class.
class. */
tssp = template_supplement_for_symbol(sym);
check_assertion(tssp != NULL);
tssp->cache->decl_info->decl_seq = class_end_decl_seq;
tssp->cache->decl_info->definition_info.decl_seq =
class_end_decl_seq;
} /* if */
if (prototype_instantiation_should_be_done_for_function(sym) &&
(!defer_function_prototype_instantiations ||
Expand Down Expand Up @@ -6468,7 +6473,7 @@ the overridden symbol.
if (compatible) {
/* Nothing more to do. */
} else if ((gpp_mode || microsoft_mode) &&
is_prototype_instantiation_context()) {
is_prototype_instantiation_or_expansion_context()) {
/* GNU and Microsoft compilers appear not to check return type
compatibility during prototype instantiations. */
#if MICROSOFT_EXTENSIONS_ALLOWED
Expand Down Expand Up @@ -16916,15 +16921,18 @@ implicitly declared member functions.
template cache information, as well as an entry to perform a
prototype instantiation when the complete definition of the
enclosing class has been seen. */
a_template_decl_info_ptr tdip =
if (!in_expansion_prototype_without_enclosing_template()) {
a_template_decl_info_ptr tdip =
get_specified_template_decl_info(/*innermost=*/TRUE);
a_reusable_token_cache reusable_cache(
a_reusable_token_cache reusable_cache(
rtsp->exception_specification->variant.token_cache);

set_template_cache_info(
set_template_cache_info(
tssp->variant.function.exception_spec_arg_cache,
reusable_cache,
tdip);
} /* if */
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
/* Expansion-only prototypes use the class fixup and element replay,
not a template declaration cache. */
check_assertion(curr_routine_fixup != NULL);
curr_routine_fixup->process_exception_spec = TRUE;
} /* if */
Expand Down Expand Up @@ -25482,8 +25490,9 @@ templates from that base template.
/*is_template_template_param_rescan*/FALSE);
new_tpl = copy_template_param_list(btpl);
templ_decl_state.decl_info->parameters = new_tpl;
templ_decl_state.decl_info->pack_expansions =
btssp->variant.function.decl_cache->decl_info->pack_expansions;
templ_decl_state.decl_info->definition_info.pack_expansions.head =
btssp->variant.function.decl_cache->decl_info->
definition_info.pack_expansions.head;
templ_decl_state.number_of_template_decl_scopes += 1;
/* Save a pointer to the template declaration information in the scope
stack entry. */
Expand Down Expand Up @@ -31023,7 +31032,7 @@ block of information that is provided if this is a member template declaration.
/* We ran into "auto" parameters: Reparse the declaration as a template
(i.e., this is an abbreviated function template). */
a_token_kind final_token = tok_semicolon;
if (is_prototype_instantiation_context()) {
if (is_prototype_instantiation_or_expansion_context()) {
/* There is an enclosing template and when that is instantiated, we
will see the abbreviated function template again. Rather than
perform two parses again, we will reuse the information we found
Expand Down Expand Up @@ -33543,14 +33552,15 @@ classes.
scope_stack_top().default_name_linkage;
#endif /* BACK_END_IS_CP_GEN_BE */
if (is_prototype_instantiation_or_cli_generic_type(class_type) ||
scope_stack_top().in_prototype_instantiation ||
in_prototype_instantiation_or_expansion_scan() ||
scope_stack_top().in_generic_definition) {
/* This is a prototype instantiation, C++/CLI generic definition, or
/* This is a prototype instantiation (including the prototype scan
of an expansion statement body), C++/CLI generic definition, or
an instantiation of a local class type, so the resulting class
is "nonreal" (i.e., based on template arguments that include
the dummy types and constants of template parameters rather than
real types and constants). */
if (scope_stack_top().in_prototype_instantiation) {
if (in_prototype_instantiation_or_expansion_scan()) {
class_state.is_nonreal_instantiation = TRUE;
class_type->variant.class_struct_union.is_nonreal_class = TRUE;
} else if (scope_stack_top().in_generic_definition) {
Expand Down Expand Up @@ -34944,8 +34954,17 @@ caller has already moved past the '[', and this routine leaves the trailing
if (symbol_is(sym, sk_variable)) {
an_error_code diag = ec_no_error;
var = sym->variant.variable.ptr;
if (!check_var_for_lambda_capture(var, /*implicit=*/FALSE,
by_ref, &diag)) {
if (var->compiler_generated && !var->is_struct_binding &&
var->source_corresp.is_local_to_function &&
type_is(var->type, tk_template_param)) {
/* The dummy parameter variable for an empty expansion
of a function parameter pack (see decl_parameter) is
not itself capturable; the real captures are created
when the enclosing context is expanded. */
var = NULL;
} else if (!check_var_for_lambda_capture(var,
/*implicit=*/FALSE,
by_ref, &diag)) {
pos_error(diag, &error_position);
var = NULL;
} else if (diag != ec_no_error) {
Expand Down Expand Up @@ -35538,8 +35557,9 @@ decl_info/locator/func_info the member to be declared.
parameters;
new_tpl = copy_template_param_list(call_op_tpl);
templ_decl_state.decl_info->parameters = new_tpl;
templ_decl_state.decl_info->pack_expansions =
call_op_tssp->variant.function.decl_cache->decl_info->pack_expansions;
templ_decl_state.decl_info->definition_info.pack_expansions.head =
call_op_tssp->variant.function.decl_cache->decl_info
->definition_info.pack_expansions.head;
templ_decl_state.number_of_template_decl_scopes += 1;
/* Save a pointer to the template declaration information in the scope
stack entry. */
Expand Down
2 changes: 2 additions & 0 deletions src/cmd_line.c
Original file line number Diff line number Diff line change
Expand Up @@ -4466,6 +4466,7 @@ default mode (e.g., exception handling).
if (!constexpr_exceptions_flag_used) {
constexpr_exceptions_enabled = TRUE;
} /* if */
expansion_statements_enabled = TRUE;
} /* if */
/* Disable "false" as a null pointer constant in C++11 mode (as per Core
issue 903). */
Expand Down Expand Up @@ -13892,6 +13893,7 @@ variables declared in cmd_line.h.
pack_indexing_enabled = FALSE;
constexpr_exceptions_enabled = FALSE;
constexpr_exceptions_flag_used = FALSE;
expansion_statements_enabled = FALSE;
} /* cmd_line_static_var_init */


Expand Down
14 changes: 14 additions & 0 deletions src/cmd_line.h
Original file line number Diff line number Diff line change
Expand Up @@ -3022,6 +3022,10 @@ EXTERN_THREAD a_boolean
/* TRUE if exceptions can be thrown and caught during
constant evaluation (a C++26 feature). */

EXTERN_THREAD a_boolean
expansion_statements_enabled;
/* TRUE if C++26 expansion statements are supported. */

/*
Macro that determines whether CTAD for alias templates should be accepted.
Alias-template CTAD is a standard feature in C++20 mode (and the global
Expand All @@ -3042,6 +3046,16 @@ warning in recent GNU and Clang C++ modes.
(pack_indexing_enabled || \
gpp_version_is(>=150000) || clangcpp_version_is(>=190000))

/*
Macro that determines whether expansion statements should be accepted.
Expansion statements are a standard feature in C++26 mode (and the global
variable expansion_statements_enabled is TRUE in that case) that is also
accepted with a warning in GNU C++11 and later modes emulating GCC 16 or
later.
*/
#define expansion_statements_allowed \
(expansion_statements_enabled || (cpp11_mode && gpp_version_is(>=160000)))

/* Process the command line arguments. */
extern void proc_command_line(int argc, char *argv[]);
#if COMPILE_MULTIPLE_SOURCE_FILES
Expand Down
57 changes: 57 additions & 0 deletions src/cp_gen_be.c
Original file line number Diff line number Diff line change
Expand Up @@ -20310,6 +20310,59 @@ Generate code for the indicated range-based-for statement.
gen_statement(statement->variant.range_based_for_loop.statement);
} /* gen_range_based_for_statement */


static void gen_expansion_statement(a_statement_ptr statement)
/*
Generate code for the indicated expansion statement.
*/
{
an_expansion_stmt_info_ptr expn_info = expn_info_of(statement);

if (expn_info->expansion_scope != NULL) {
push_name_context(expn_info->expansion_scope);
} /* if */
write_tok_str("template for (");
if (expn_info->initialization != NULL) {
Comment thread
daveedvdv-nvidia marked this conversation as resolved.
Resolved
/* Generate the initialization statement. */
gen_init_statement_or_statement(
get_for_init_statement(expn_info->initialization));
} /* if */
gen_variable_decl(/*is_condition=*/FALSE, /*is_iterator=*/TRUE,
/*for_init=*/FALSE, /*suppress_specifiers=*/FALSE,
(a_boolean *)NULL);
write_tok_str(" : ");
if (expn_info->initializer_is_list) {
/* Generate the initializer list. */
write_tok_ch('{');
for (an_expr_node_ptr expr = expn_info->initializer;
expr != NULL;
expr = expr->next) {
if (expr != expn_info->initializer) {
write_tok_str(", ");
} /* if */
skip_embedded_declarations();
gen_expr(expr, /*need_parens=*/expr_has_comma_operation(expr),
/*obj_expr_of_mfunc_operator=*/FALSE);
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
} /* for */
write_tok_ch('}');
} else {
/* Generate the initializer expression. */
check_assertion(expn_info->initializer != NULL);
gen_expression(expn_info->initializer);
} /* if */
write_tok_str(") ");
/* The body is a template definition even outside an ordinary template;
generate it in prototype form. */
Value_saver<a_boolean> prototype_context_saver(
&in_prototype_instantiation_context, TRUE);
if (expn_info->iterator_scope != NULL) {
push_name_context(expn_info->iterator_scope);
} /* if */
gen_statement(statement->variant.expansion_statement.statement);
Comment thread
daveedvdv-nvidia marked this conversation as resolved.
Resolved
if (expn_info->iterator_scope != NULL) pop_name_context();
if (expn_info->expansion_scope != NULL) pop_name_context();
} /* gen_expansion_statement */

#if MICROSOFT_EXTENSIONS_ALLOWED

static void gen_for_each_statement(a_statement_ptr statement)
Expand Down Expand Up @@ -22657,6 +22710,10 @@ one that yields the value) of a statement expression.
/* range-based-for statement. */
gen_range_based_for_statement(statement);
break;
case stmk_expansion_statement:
/* Expansion statement. */
gen_expansion_statement(statement);
break;
#if MICROSOFT_EXTENSIONS_ALLOWED
case stmk_for_each:
/* "for each" statement. */
Expand Down
Loading
Loading