Skip to content

[clang] Add regression tests for narrowing with is_constant_evaluated. #142885

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
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
11 changes: 11 additions & 0 deletions clang/test/SemaCXX/builtin-is-constant-evaluated.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,3 +143,14 @@ namespace fold_initializer {
const float A::f = __builtin_is_constant_evaluated();
static_assert(fold(A::f == 1.0f));
}

namespace narrowing {
struct X { unsigned u; };
constexpr int f(X x) {return x.u;}
void g() {
static_assert(f({0xFFFFFFFFLL + __builtin_is_constant_evaluated()}) == 0);
f({0x100000000LL - __builtin_is_constant_evaluated()}); // expected-error {{constant expression evaluates to 4294967296}} \
// expected-warning {{implicit conversion}} \
// expected-note {{insert an explicit cast to silence this issue}}
}
}
Loading