Files
clang-p2996/clang/test/SemaTemplate/cxx2a-constraint-caching.cpp
Richard Smith 2f8ac0758b PR50402: Use proper constant evaluation rules for checking constraint
satisfaction.

Previously we used the rules for constant folding in a non-constant
context, meaning that we'd incorrectly accept foldable non-constant
expressions and that std::is_constant_evaluated() would evaluate to
false.
2021-05-19 16:02:53 -07:00

35 lines
816 B
C++

// RUN: %clang_cc1 -std=c++2a -verify %s
// RUN: %clang_cc1 -std=c++2a -verify %s -fno-concept-satisfaction-caching -DNO_CACHE
// expected-no-diagnostics
template<typename T>
concept C = (f(T()), true);
template<typename T>
constexpr bool foo() { return false; }
template<typename T>
requires (f(T()), true)
constexpr bool foo() requires (f(T()), true) { return true; }
namespace a {
struct A {};
constexpr void f(A a) {}
}
static_assert(C<a::A>);
static_assert(foo<a::A>());
namespace a {
// This makes calls to f ambiguous, but the second check will still succeed
// because the constraint satisfaction results are cached.
constexpr void f(A a, int = 2) {}
}
#ifdef NO_CACHE
static_assert(!C<a::A>);
static_assert(!foo<a::A>());
#else
static_assert(C<a::A>);
static_assert(foo<a::A>());
#endif