Skip to content

Commit 6112d12

Browse files
committed
[Clang] prevent assertion failure in value-dependent initializer expressions
1 parent 7cbb365 commit 6112d12

File tree

3 files changed

+14
-0
lines changed

3 files changed

+14
-0
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -517,6 +517,7 @@ Bug Fixes to C++ Support
517517
certain situations. (#GH47400), (#GH90896)
518518
- Fix erroneous templated array size calculation leading to crashes in generated code. (#GH41441)
519519
- During the lookup for a base class name, non-type names are ignored. (#GH16855)
520+
- Fixed an assertion failure when evaluating constant expressions in value-dependent initializers (#GH112140)
520521

521522
Bug Fixes to AST Handling
522523
^^^^^^^^^^^^^^^^^^^^^^^^^

clang/lib/AST/ExprConstant.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11536,6 +11536,9 @@ bool ArrayExprEvaluator::VisitCXXParenListOrInitListExpr(
1153611536
LValue Subobject = This;
1153711537
Subobject.addArray(Info, ExprToVisit, CAT);
1153811538
auto Eval = [&](const Expr *Init, unsigned ArrayIndex) {
11539+
if (Init->isValueDependent())
11540+
return EvaluateDependentExpr(Init, Info);
11541+
1153911542
if (!EvaluateInPlace(Result.getArrayInitializedElt(ArrayIndex), Info,
1154011543
Subobject, Init) ||
1154111544
!HandleLValueArrayAdjustment(Info, Init, Subobject,

clang/test/SemaCXX/constant-expression-cxx11.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2564,3 +2564,13 @@ GH50055::E2 GlobalInitNotCE2 = GH50055::testDefaultArgForParam(); // ok, not a c
25642564
constexpr GH50055::E2 GlobalInitCE = (GH50055::E2)-1;
25652565
// expected-error@-1 {{constexpr variable 'GlobalInitCE' must be initialized by a constant expression}}
25662566
// expected-note@-2 {{integer value -1 is outside the valid range of values [0, 7] for the enumeration type 'E2'}}
2567+
2568+
namespace GH {
2569+
struct S {
2570+
constexpr S(const int &a = ) { } // expected-error {{expected expression}}
2571+
};
2572+
2573+
void foo() {
2574+
constexpr S s[2] = { }; // expected-error {{constexpr variable 's' must be initialized by a constant expression}}
2575+
}
2576+
}

0 commit comments

Comments
 (0)