Skip to content

Commit de6ddae

Browse files
committed
Revert "Don't treat 'T &forward(T&&)' as builtin."
This reverts commit e43c93d as the parent https://reviews.llvm.org/D123345 breaks the AIX CI.
1 parent c231471 commit de6ddae

File tree

3 files changed

+1
-27
lines changed

3 files changed

+1
-27
lines changed

clang/lib/Sema/SemaTemplateInstantiateDecl.cpp

-14
Original file line numberDiff line numberDiff line change
@@ -621,20 +621,6 @@ static bool isRelevantAttr(Sema &S, const Decl *D, const Attr *A) {
621621
return true;
622622
}
623623

624-
if (const auto *BA = dyn_cast<BuiltinAttr>(A)) {
625-
// Do not treat 'std::forward' as a builtin if it takes an rvalue reference
626-
// type and returns an lvalue reference type. The library implementation
627-
// will produce an error in this case; don't get in its way.
628-
if (BA->getID() == Builtin::BIforward) {
629-
const FunctionDecl *FD = dyn_cast<FunctionDecl>(D);
630-
if (FD && FD->getNumParams() >= 1 &&
631-
FD->getParamDecl(0)->getType()->isRValueReferenceType() &&
632-
FD->getReturnType()->isLValueReferenceType()) {
633-
return false;
634-
}
635-
}
636-
}
637-
638624
return true;
639625
}
640626

clang/test/SemaCXX/builtin-std-move.cpp

-12
Original file line numberDiff line numberDiff line change
@@ -30,18 +30,11 @@ namespace std {
3030
template<typename T> struct remove_reference<T&> { using type = T; };
3131
template<typename T> struct remove_reference<T&&> { using type = T; };
3232

33-
template<typename T> struct is_lvalue_reference { static constexpr bool value = false; };
34-
template<typename T> struct is_lvalue_reference<T&> { static constexpr bool value = true; };
35-
3633
template<typename T> CONSTEXPR T &&forward(typename remove_reference<T>::type &x) {
3734
static_assert(T::moveable, "instantiated forward"); // expected-error {{no member named 'moveable' in 'B'}}
3835
// expected-error@-1 {{no member named 'moveable' in 'C'}}
3936
return static_cast<T&&>(x);
4037
}
41-
template<typename T> CONSTEXPR T &&forward(typename remove_reference<T>::type &&x) {
42-
static_assert(!is_lvalue_reference<T>::value, "should not forward rval as lval"); // expected-error {{static_assert failed}}
43-
return static_cast<T&&>(x);
44-
}
4538

4639
template<typename T> CONSTEXPR const T &as_const(T &x) {
4740
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");
8376
// expected-note@#call {{}}
8477
#endif
8578

86-
A &forward_rval_as_lval() {
87-
std::forward<A&&>(A()); // expected-warning {{const attribute}}
88-
return std::forward<A&>(A()); // expected-note {{instantiation of}}
89-
}
90-
9179
struct B {};
9280
B &&(*pMove)(B&) = std::move; // #1 expected-note {{instantiation of}}
9381
B &&(*pMoveIfNoexcept)(B&) = &std::move_if_noexcept; // #2 expected-note {{instantiation of}}

libcxx/test/std/utilities/utility/forward/forward.fail.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ const A csource() {return A();}
2222
int main(int, char**)
2323
{
2424
{
25-
(void)std::forward<A&>(source()); // expected-note {{requested here}}
25+
std::forward<A&>(source()); // expected-note {{requested here}}
2626
// expected-error-re@*:* 1 {{static_assert failed{{.*}} "cannot forward an rvalue as an lvalue"}}
2727
}
2828
{

0 commit comments

Comments
 (0)