Skip to content

Commit d0db54e

Browse files
committed
[clang] Update test according to P1937
https://wg21.link/p1937 proposes that in unevaluated contexts, consteval functions should not be immediately evaluated. Clang implemented p1937 a while ago, its behavior is correct and the test needs an update. Reviewed By: aaron.ballman, shafik Differential Revision: https://reviews.llvm.org/D145362
1 parent 3391246 commit d0db54e

File tree

1 file changed

+17
-7
lines changed

1 file changed

+17
-7
lines changed

clang/test/CXX/expr/expr.const/p8-2a.cpp

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
// expected-no-diagnostics
44

5-
namespace P1073R3 {
5+
namespace P1937R2 {
66
struct N {
77
constexpr N() {}
88
N(N const&) = delete;
@@ -11,12 +11,22 @@ struct N {
1111
template<typename T> constexpr void bad_assert_copyable() { T t; T t2 = t; }
1212
using ineffective = decltype(bad_assert_copyable<N>());
1313

14-
// bad_assert_copyable<N> is not needed for constant evaluation
15-
// (and thus not instantiated)
1614
template<typename T> consteval void assert_copyable() { T t; T t2 = t; }
15+
// Prior to P1937R2 consteval functions were evaluated even in otherwise
16+
// unevaluated context, now this is well-formed.
1717
using check = decltype(assert_copyable<N>());
18-
// FIXME: this should give an error because assert_copyable<N> is instantiated
19-
// (because it is needed for constant evaluation), but the attempt to copy t is
20-
// ill-formed.
21-
} // namespace P1073R3
18+
19+
template<typename T>
20+
__add_rvalue_reference(T) declval();
21+
22+
constexpr auto add1(auto lhs, auto rhs) {
23+
return lhs + rhs;
24+
}
25+
using T = decltype(add1(declval<int>(), declval<int>()));
26+
27+
consteval auto add2(auto lhs, auto rhs) {
28+
return lhs + rhs;
29+
}
30+
using T = decltype(add2(declval<int>(), declval<int>()));
31+
} // namespace P1937R2
2232

0 commit comments

Comments
 (0)