Repository navigation
Description
Discussed in #573
Originally posted by jakub-labenski November 20, 2026
Issue Summary
The C++-generating back end can crash when the right operand of a
short-circuited && or || contains a GNU statement expression with a
local declaration.
Reproducing Source Code
template<typename T> struct operators {
template<typename U> bool operator&&(U);
template<typename U> bool operator||(U);
};
template<typename T> struct wrapper { bool has_value(); };
void test() {
operators<int> ops; (void)ops;
(void)(0 && ({ auto value(wrapper<wrapper<int>>{}); value; }).has_value());
(void)(1 || ({ auto value(wrapper<wrapper<int>>{}); value; }).has_value());
}
bool nested_short_circuit() {
return (false && ({ wrapper<int> value; value.has_value(); })) ==
(true || ({ struct local { bool value; }; local item{false};
item.value; }));
}Command-line Options
cpfe-cp -w --g++ --gnu_version=150200 test.cpp
Type of Issue
[Front End] This code SHOULD compile with these options.
Additional Details
When the front end folds (0 && x) / (1 || x) to a constant
(exprutil.c), it calls eliminate_stmt_expr_refs_if_operand_dropped() on
the right operand. That removes the source-sequence entries for that operand's
declarations. But in contexts where constant expressions are recorded
(curr_expr_kind_is_one_in_which_const_exprs_are_recorded()), the original
expression is kept as the backing expression, and the C++ generator still
emits it. It then refers to declarations whose entries are gone.
Reproducing (Standard) Configuration(s)
linux-gcc-debug
Reproducing (Non-standard) Configuration
No response
I acknowledge that:
- I have checked open issues and existing discussions before filing this report.
- The reproducing source code that I have provided does not depend on headers that I have not included with my submission.
- I have reduced the reproducing source code to the best of my ability.
- I have selected at least one standard configuration or uploaded a non-standard configuration dump.
- I understand code shared via this form is NOT confidential.
- I have permission to share the reproducing source code and grant permission for the project to use the source code (or derivatives of the source code) to create tests.
- I agree that any tests created using the reproducing source code (or deriatives of it) will be licensed under project license unless I included a
LICENSE.txtfile in my.zipor.tar.gzupload. If I included aLICENSE.txtfile, any tests created using the reproducing source code will be governed by the terms of the license I provided instead.
Activity
Preserve GNU statement expressions in folded logical operands. [GH ed…
Preserve GNU statement expressions in folded logical operands. [GH ed…
Preserve GNU statement expressions in folded logical operands. [GH ed…
Sync upstream #pragma GCC diagnostic IL and Changes [GH edgcpp#182, GH …