[clang] d0db54e - [clang] Update test according to P1937

Mariya Podchishchaeva via cfe-commits cfe-commits at lists.llvm.org
Tue Mar 7 08:32:13 PST 2023


Author: Mariya Podchishchaeva
Date: 2023-03-07T11:30:25-05:00
New Revision: d0db54e0dd3272a044407a6394cae47c84cd3a70

URL: https://github.com/llvm/llvm-project/commit/d0db54e0dd3272a044407a6394cae47c84cd3a70
DIFF: https://github.com/llvm/llvm-project/commit/d0db54e0dd3272a044407a6394cae47c84cd3a70.diff

LOG: [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

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/clang/test/CXX/expr/expr.const/p8-2a.cpp b/clang/test/CXX/expr/expr.const/p8-2a.cpp
index b8bee64b0aae2..c13b32a165dbd 100644
--- a/clang/test/CXX/expr/expr.const/p8-2a.cpp
+++ b/clang/test/CXX/expr/expr.const/p8-2a.cpp
@@ -2,7 +2,7 @@
 
 // expected-no-diagnostics
 
-namespace P1073R3 {
+namespace P1937R2 {
 struct N {
   constexpr N() {}
   N(N const&) = delete;
@@ -11,12 +11,22 @@ struct N {
 template<typename T> constexpr void bad_assert_copyable() { T t; T t2 = t; }
 using ineffective = decltype(bad_assert_copyable<N>());
 
-// bad_assert_copyable<N> is not needed for constant evaluation
-// (and thus not instantiated)
 template<typename T> consteval void assert_copyable() { T t; T t2 = t; }
+// Prior to P1937R2 consteval functions were evaluated even in otherwise
+// unevaluated context, now this is well-formed.
 using check = decltype(assert_copyable<N>());
-// FIXME: this should give an error because assert_copyable<N> is instantiated
-// (because it is needed for constant evaluation), but the attempt to copy t is
-// ill-formed.
-} // namespace P1073R3
+
+template<typename T>
+__add_rvalue_reference(T) declval();
+
+constexpr auto add1(auto lhs, auto rhs) {
+    return lhs + rhs;
+}
+using T = decltype(add1(declval<int>(), declval<int>()));
+
+consteval auto add2(auto lhs, auto rhs) {
+    return lhs + rhs;
+}
+using T = decltype(add2(declval<int>(), declval<int>()));
+} // namespace P1937R2
 


        


More information about the cfe-commits mailing list