Files
clang-p2996/clang/test/CodeGenCXX/cxx2b-consteval-if.cpp
Corentin Jabot 424733c12a Implement if consteval (P1938)
Modify the IfStmt node to suppoort constant evaluated expressions.

Add a new ExpressionEvaluationContext::ImmediateFunctionContext to
keep track of immediate function contexts.

This proved easier/better/probably more efficient than walking the AST
backward as it allows diagnosing nested if consteval statements.
2021-10-05 08:04:14 -04:00

29 lines
642 B
C++

// RUN: %clang_cc1 -std=c++2b %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();
}