Eric Fiselier 000f25a37e Make move and forward work in C++03.
These functions are key to allowing the use of rvalues and variadics
in C++03 mode. Everything works the same as in C++11, except for one
tangentially related case:

struct T {
  T(T &&) = default;
};

In C++11, T has a deleted copy constructor. But in C++03 Clang gives
it both a move and a copy constructor. This seems reasonable enough
given the extensions it's using.

The other changes in this patch were the minimal set required
to keep the tests passing after the move/forward change. Most notably
the removal of the `__rv<unique_ptr>` hack that was present
in an attempt to make unique_ptr move only without language support.

llvm-svn: 364063
2019-06-21 15:20:55 +00:00

49 lines
1.3 KiB
C++

//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
// test forward
#include <utility>
#include "test_macros.h"
struct A
{
};
A source() {return A();}
const A csource() {return A();}
int main(int, char**)
{
{
std::forward<A&>(source()); // expected-note {{requested here}}
// expected-error-re@type_traits:* 1 {{static_assert failed{{.*}} "can not forward an rvalue as an lvalue"}}
}
{
const A ca = A();
std::forward<A&>(ca); // expected-error {{no matching function for call to 'forward'}}
}
{
std::forward<A&>(csource()); // expected-error {{no matching function for call to 'forward'}}
}
{
const A ca = A();
std::forward<A>(ca); // expected-error {{no matching function for call to 'forward'}}
}
{
std::forward<A>(csource()); // expected-error {{no matching function for call to 'forward'}}
}
{
A a;
std::forward(a); // expected-error {{no matching function for call to 'forward'}}
}
return 0;
}