Skip to content

Commit

Permalink
Revert "Don't treat 'T &forward(T&&)' as builtin."
Browse files Browse the repository at this point in the history
This reverts commit e43c93d as the
parent https://reviews.llvm.org/D123345 breaks the AIX CI.
  • Loading branch information
daltenty committed Apr 20, 2022
1 parent c231471 commit de6ddae
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 27 deletions.
14 changes: 0 additions & 14 deletions clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
12 changes: 0 additions & 12 deletions clang/test/SemaCXX/builtin-std-move.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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@-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'}}
Expand Down Expand Up @@ -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}}
Expand Down
2 changes: 1 addition & 1 deletion libcxx/test/std/utilities/utility/forward/forward.fail.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"}}
}
{
Expand Down

0 comments on commit de6ddae

Please sign in to comment.