Skip to content

Commit 06cc20c

Browse files
authored
[clang][bytecode] Diagnose out-of-bounds enum values in .... (#163530)
... non-constexpr variable initializers.
1 parent 0ede563 commit 06cc20c

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

clang/lib/AST/ByteCode/Interp.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1358,9 +1358,6 @@ bool Free(InterpState &S, CodePtr OpPC, bool DeleteIsArrayForm,
13581358

13591359
void diagnoseEnumValue(InterpState &S, CodePtr OpPC, const EnumDecl *ED,
13601360
const APSInt &Value) {
1361-
if (S.EvaluatingDecl && !S.EvaluatingDecl->isConstexpr())
1362-
return;
1363-
13641361
llvm::APInt Min;
13651362
llvm::APInt Max;
13661363
ED->getValueRange(Max, Min);

clang/test/AST/ByteCode/cxx11.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,14 @@ void testValueInRangeOfEnumerationValues() {
146146

147147
const NumberType neg_one = (NumberType) ((NumberType) 0 - (NumberType) 1); // ok, not a constant expression context
148148
}
149+
struct EnumTest {
150+
enum type {
151+
Type1,
152+
BOUND
153+
};
154+
static const type binding_completed = type(BOUND + 1); // both-error {{in-class initializer for static data member is not a constant expression}} \
155+
// both-note {{integer value 2 is outside the valid range of values}}
156+
};
149157

150158
template<class T, unsigned size> struct Bitfield {
151159
static constexpr T max = static_cast<T>((1 << size) - 1);

0 commit comments

Comments
 (0)