mirror of
https://github.com/llvm/llvm-project.git
synced 2025-04-27 13:36:07 +00:00

Summary: C++1z 6.4.1/p2: If the if statement is of the form if constexpr, the value of the condition shall be a contextually converted constant expression of type bool [...] C++1z 5.20/p4: [...] A contextually converted constant expression of type bool is an expression, contextually converted to bool (Clause4), where the converted expression is a constant expression and the conversion sequence contains only the conversions above. [...] Contextually converting result of an expression `e` to a Boolean value requires `bool t(e)` to be well-formed. An explicit conversion function is only considered as a user-defined conversion for direct-initialization, which is essentially what //contextually converted to bool// requires. Also, fixes PR28470. Reviewers: rsmith Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D24158 llvm-svn: 280838
35 lines
666 B
C++
35 lines
666 B
C++
// RUN: %clang_cc1 -std=c++1z %s -emit-llvm -o - | FileCheck %s --implicit-check-not=should_not_be_used
|
|
|
|
void should_be_used_1();
|
|
void should_be_used_2();
|
|
void should_be_used_3();
|
|
void should_not_be_used();
|
|
|
|
struct A {
|
|
constexpr explicit operator bool() const {
|
|
return true;
|
|
}
|
|
};
|
|
|
|
void f() {
|
|
if constexpr (false)
|
|
should_not_be_used();
|
|
else
|
|
should_be_used_1();
|
|
|
|
if constexpr (true || ({ label: false; }))
|
|
should_be_used_2();
|
|
else {
|
|
goto foo;
|
|
foo: should_not_be_used();
|
|
}
|
|
if constexpr (A())
|
|
should_be_used_3();
|
|
else
|
|
should_not_be_used();
|
|
}
|
|
|
|
// CHECK: should_be_used_1
|
|
// CHECK: should_be_used_2
|
|
// CHECK: should_be_used_3
|