57 lines · cpp
1// RUN: %clang_cc1 -std=c++23 %s -emit-llvm -o - | FileCheck %s2// RUN: %clang_cc1 -std=c++23 %s -emit-llvm -o - -fexperimental-new-constant-interpreter | FileCheck %s3 4void should_be_used_1();5void should_be_used_2();6void should_be_used_3();7constexpr void should_not_be_used() {}8 9constexpr void f() {10 if consteval {11 should_not_be_used(); // CHECK-NOT: call {{.*}}should_not_be_used12 } else {13 should_be_used_1(); // CHECK: call {{.*}}should_be_used_114 }15 16 if !consteval {17 should_be_used_2(); // CHECK: call {{.*}}should_be_used_218 }19 20 if !consteval {21 should_be_used_3(); // CHECK: call {{.*}}should_be_used_322 } else {23 should_not_be_used(); // CHECK-NOT: call {{.*}}should_not_be_used24 }25}26 27void g() {28 f();29}30 31namespace GH55638 {32 33constexpr bool is_constant_evaluated() noexcept {34 if consteval { return true; } else { return false; }35}36 37constexpr int compiletime(int) {38 return 2;39}40 41constexpr int runtime(int) {42 return 1;43}44 45constexpr int test(int x) {46 if(is_constant_evaluated())47 return compiletime(x); // CHECK-NOT: call {{.*}}compiletime48 return runtime(x); // CHECK: call {{.*}}runtime49}50 51int f(int x) {52 x = test(x);53 return x;54}55 56}57