llvm-project/clang/test/CXX
Matheus Izvekov 03282f2fe1 [clang] C++98 implicit moves are back with a vengeance
After taking C++98 implicit moves out in D104500,
we put it back in, but now in a new form which preserves
compatibility with pure C++98 programs, while at the same time
giving almost all the goodies from P1825.

* We use the exact same rules as C++20 with regards to which
  id-expressions are move eligible. The previous
  incarnation would only benefit from the proper subset which is
  copy ellidable. This means we can implicit move, in addition:
  * Parameters.
  * RValue references.
  * Exception variables.
  * Variables with higher-than-natural required alignment.
  * Objects with different type from the function return type.
* We preserve the two-overload resolution, with one small tweak to the
  first one: If we either pick a (possibly converting) constructor which
  does not take an rvalue reference, or a user conversion operator which
  is not ref-qualified, we abort into the second overload resolution.

This gives C++98 almost all the implicit move patterns which we had created test
cases for, while at the same time preserving the meaning of these
three patterns, which are found in pure C++98 programs:
* Classes with both const and non-const copy constructors, but no move
  constructors, continue to have their non-const copy constructor
  selected.
* We continue to reject as ambiguous the following pattern:
```
struct A { A(B &); };
struct B { operator A(); };
A foo(B x) { return x; }
```
* We continue to pick the copy constructor in the following pattern:
```
class AutoPtrRef { };
struct AutoPtr {
  AutoPtr(AutoPtr &);
  AutoPtr();

  AutoPtr(AutoPtrRef);
  operator AutoPtrRef();
};
AutoPtr test_auto_ptr() {
  AutoPtr p;
  return p;
}
```

Signed-off-by: Matheus Izvekov <mizvekov@gmail.com>

Reviewed By: Quuxplusone

Differential Revision: https://reviews.llvm.org/D105756
2021-07-13 19:16:49 +02:00
..
basic [Sema] Fold VLAs to constant arrays in a few more contexts 2020-12-04 10:03:23 -05:00
class [clang] C++98 implicit moves are back with a vengeance 2021-07-13 19:16:49 +02:00
class.access Remove redundant check for access in the conversion from the naming 2020-11-29 19:21:59 -08:00
class.derived Defer checking for mismatches between the deletedness of and overriding 2020-03-12 13:07:22 -07:00
conv [Sema][C++] Propagate conversion kind to specialize the diagnostics 2020-02-25 16:05:37 +00:00
cpp [Clang] Add __STDCPP_THREADS__ to standard predefine macros 2020-11-22 16:05:53 -08:00
dcl [clang] Fix ICE on invalid type parameters for concepts 2021-03-13 01:23:02 +01:00
dcl.dcl [clang] Implement P2266 Simpler implicit move 2021-06-18 17:08:59 +02:00
dcl.decl Remove unnecessary triple from test 2021-06-15 09:49:45 -07:00
drs [clang] Stop providing builtin overload candidate for relational function pointer comparisons 2021-06-26 00:08:02 +02:00
except [CodeGen] Apply 'nonnull' and 'dereferenceable(N)' to 'this' pointer 2020-11-16 17:39:17 -08:00
expr [clang] Stop providing builtin overload candidate for relational function pointer comparisons 2021-06-26 00:08:02 +02:00
lex Add type information to integral template argument if required. 2021-05-12 19:00:08 +00:00
module Improve diagnostics for missing import / #include of module. 2020-04-28 18:41:14 -07:00
modules-ts Fix a diagnoses-valid bug with using declarations 2021-06-04 15:52:07 -04:00
over [c++20] Further extend the set of comparisons broken by C++20 that we 2020-03-20 14:22:48 -07:00
special [clang] tests: cleanup, update and add some new ones 2021-04-09 17:24:08 +02:00
stmt.stmt Partially implement P1401R5 (Narrowing contextual conversions to bool) 2021-07-12 08:06:27 -04:00
temp [clang] Implement P2266 Simpler implicit move 2021-06-18 17:08:59 +02:00