Debian Codegraph @

clang/test/CodeGenCXX/cxx2b-consteval-if.cpp

raw
1 // RUN: %clang_cc1 -std=c++23 %s -emit-llvm -o - | FileCheck %s
2
3 void should_be_used_1();
4 void should_be_used_2();
5 void should_be_used_3();
6 constexpr void should_not_be_used() {}
7
8 constexpr void f() {
9 if consteval {
10 should_not_be_used(); // CHECK-NOT: call {{.*}}should_not_be_used
11 } else {
12 should_be_used_1(); // CHECK: call {{.*}}should_be_used_1
13 }
14
15 if !consteval {
16 should_be_used_2(); // CHECK: call {{.*}}should_be_used_2
17 }
18
19 if !consteval {
20 should_be_used_3(); // CHECK: call {{.*}}should_be_used_3
21 } else {
22 should_not_be_used(); // CHECK-NOT: call {{.*}}should_not_be_used
23 }
24 }
25
26 void g() {
27 f();
28 }
29
30 namespace GH55638 {
31
32 constexpr bool is_constant_evaluated() noexcept {
33 if consteval { return true; } else { return false; }
34 }
35
36 constexpr int compiletime(int) {
37 return 2;
38 }
39
40 constexpr int runtime(int) {
41 return 1;
42 }
43
44 constexpr int test(int x) {
45 if(is_constant_evaluated())
46 return compiletime(x); // CHECK-NOT: call {{.*}}compiletime
47 return runtime(x); // CHECK: call {{.*}}runtime
48 }
49
50 int f(int x) {
51 x = test(x);
52 return x;
53 }
54
55 }