Files
clang-p2996/clang/test/CodeGenCXX/cxx2b-consteval-if.cpp
Mark de Wever ba15d186e5 [clang] Use -std=c++23 instead of -std=c++2b
During the ISO C++ Committee meeting plenary session the C++23 Standard
has been voted as technical complete.

This updates the reference to c++2b to c++23 and updates the __cplusplus
macro.

Drive-by fixes c++1z -> c++17 and c++2a -> c++20 when seen.

Reviewed By: aaron.ballman

Differential Revision: https://reviews.llvm.org/D149553
2023-05-04 19:19:52 +02:00

56 lines
1.1 KiB
C++

// RUN: %clang_cc1 -std=c++23 %s -emit-llvm -o - | FileCheck %s
void should_be_used_1();
void should_be_used_2();
void should_be_used_3();
constexpr void should_not_be_used() {}
constexpr void f() {
if consteval {
should_not_be_used(); // CHECK-NOT: call {{.*}}should_not_be_used
} else {
should_be_used_1(); // CHECK: call {{.*}}should_be_used_1
}
if !consteval {
should_be_used_2(); // CHECK: call {{.*}}should_be_used_2
}
if !consteval {
should_be_used_3(); // CHECK: call {{.*}}should_be_used_3
} else {
should_not_be_used(); // CHECK-NOT: call {{.*}}should_not_be_used
}
}
void g() {
f();
}
namespace GH55638 {
constexpr bool is_constant_evaluated() noexcept {
if consteval { return true; } else { return false; }
}
constexpr int compiletime(int) {
return 2;
}
constexpr int runtime(int) {
return 1;
}
constexpr int test(int x) {
if(is_constant_evaluated())
return compiletime(x); // CHECK-NOT: call {{.*}}compiletime
return runtime(x); // CHECK: call {{.*}}runtime
}
int f(int x) {
x = test(x);
return x;
}
}