Skip to content

Commit 19c323b

Browse files
efriedma-quicrorth
authored andcommitted
[clang] Add regression tests for narrowing with is_constant_evaluated. (llvm#142885)
As discussed in llvm#142707, in the context of determining whether a conversion is a narrowing conversion, is_constant_evaluation should be false, even it's a subexpression of a manifestly constant-evaluated expression.
1 parent ce2e57f commit 19c323b

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

clang/test/SemaCXX/builtin-is-constant-evaluated.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,3 +143,14 @@ namespace fold_initializer {
143143
const float A::f = __builtin_is_constant_evaluated();
144144
static_assert(fold(A::f == 1.0f));
145145
}
146+
147+
namespace narrowing {
148+
struct X { unsigned u; };
149+
constexpr int f(X x) {return x.u;}
150+
void g() {
151+
static_assert(f({0xFFFFFFFFLL + __builtin_is_constant_evaluated()}) == 0);
152+
f({0x100000000LL - __builtin_is_constant_evaluated()}); // expected-error {{constant expression evaluates to 4294967296}} \
153+
// expected-warning {{implicit conversion}} \
154+
// expected-note {{insert an explicit cast to silence this issue}}
155+
}
156+
}

0 commit comments

Comments
 (0)