[clang] de6ddae - Revert "Don't treat 'T &forward(T&&)' as builtin."

David Tenty via cfe-commits cfe-commits at lists.llvm.org
Wed Apr 20 16:15:09 PDT 2022


Author: David Tenty
Date: 2022-04-20T19:14:36-04:00
New Revision: de6ddaeef3aaa8a9ae3663c12cdb57d9afc0f906

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

LOG: Revert "Don't treat 'T &forward(T&&)' as builtin."

This reverts commit e43c93dd63cca295ef26ab69cd305816a71d45fd as the
parent https://reviews.llvm.org/D123345 breaks the AIX CI.

Added: 
    

Modified: 
    clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
    clang/test/SemaCXX/builtin-std-move.cpp
    libcxx/test/std/utilities/utility/forward/forward.fail.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
index f11a1748e5c68..8b0147fc66c36 100644
--- a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
+++ b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
@@ -621,20 +621,6 @@ static bool isRelevantAttr(Sema &S, const Decl *D, const Attr *A) {
     return true;
   }
 
-  if (const auto *BA = dyn_cast<BuiltinAttr>(A)) {
-    // Do not treat 'std::forward' as a builtin if it takes an rvalue reference
-    // type and returns an lvalue reference type. The library implementation
-    // will produce an error in this case; don't get in its way.
-    if (BA->getID() == Builtin::BIforward) {
-      const FunctionDecl *FD = dyn_cast<FunctionDecl>(D);
-      if (FD && FD->getNumParams() >= 1 &&
-          FD->getParamDecl(0)->getType()->isRValueReferenceType() &&
-          FD->getReturnType()->isLValueReferenceType()) {
-        return false;
-      }
-    }
-  }
-
   return true;
 }
 

diff  --git a/clang/test/SemaCXX/builtin-std-move.cpp b/clang/test/SemaCXX/builtin-std-move.cpp
index 7f1b01e43d788..a53e57c86c14c 100644
--- a/clang/test/SemaCXX/builtin-std-move.cpp
+++ b/clang/test/SemaCXX/builtin-std-move.cpp
@@ -30,18 +30,11 @@ namespace std {
   template<typename T> struct remove_reference<T&> { using type = T; };
   template<typename T> struct remove_reference<T&&> { using type = T; };
 
-  template<typename T> struct is_lvalue_reference { static constexpr bool value = false; };
-  template<typename T> struct is_lvalue_reference<T&> { static constexpr bool value = true; };
-
   template<typename T> CONSTEXPR T &&forward(typename remove_reference<T>::type &x) {
     static_assert(T::moveable, "instantiated forward"); // expected-error {{no member named 'moveable' in 'B'}}
                                                         // expected-error at -1 {{no member named 'moveable' in 'C'}}
     return static_cast<T&&>(x);
   }
-  template<typename T> CONSTEXPR T &&forward(typename remove_reference<T>::type &&x) {
-    static_assert(!is_lvalue_reference<T>::value, "should not forward rval as lval"); // expected-error {{static_assert failed}}
-    return static_cast<T&&>(x);
-  }
 
   template<typename T> CONSTEXPR const T &as_const(T &x) {
     static_assert(T::moveable, "instantiated as_const"); // expected-error {{no member named 'moveable' in 'B'}}
@@ -83,11 +76,6 @@ static_assert(f({}), "should be constexpr");
 // expected-note@#call {{}}
 #endif
 
-A &forward_rval_as_lval() {
-  std::forward<A&&>(A()); // expected-warning {{const attribute}}
-  return std::forward<A&>(A()); // expected-note {{instantiation of}}
-}
-
 struct B {};
 B &&(*pMove)(B&) = std::move; // #1 expected-note {{instantiation of}}
 B &&(*pMoveIfNoexcept)(B&) = &std::move_if_noexcept; // #2 expected-note {{instantiation of}}

diff  --git a/libcxx/test/std/utilities/utility/forward/forward.fail.cpp b/libcxx/test/std/utilities/utility/forward/forward.fail.cpp
index f913b835c2248..4d7790a751481 100644
--- a/libcxx/test/std/utilities/utility/forward/forward.fail.cpp
+++ b/libcxx/test/std/utilities/utility/forward/forward.fail.cpp
@@ -22,7 +22,7 @@ const A csource() {return A();}
 int main(int, char**)
 {
     {
-        (void)std::forward<A&>(source());  // expected-note {{requested here}}
+        std::forward<A&>(source());  // expected-note {{requested here}}
         // expected-error-re@*:* 1 {{static_assert failed{{.*}} "cannot forward an rvalue as an lvalue"}}
     }
     {


        


More information about the cfe-commits mailing list