]> granicus.if.org Git - clang/commit
[Sema] Allow static_cast<T&&>(e) to check explicit conversions for non-reference...
authorEric Fiselier <eric@efcs.ca>
Thu, 3 Nov 2016 02:13:17 +0000 (02:13 +0000)
committerEric Fiselier <eric@efcs.ca>
Thu, 3 Nov 2016 02:13:17 +0000 (02:13 +0000)
commitecafbe5a312763aa43ff329d2c54db4e40ade1da
tree409e47d7c445646e3ae52fccb502e8181558a65c
parent7b08e8d3886cb5c9e4254af57ca0c6cc0d508a1f
[Sema] Allow static_cast<T&&>(e) to check explicit conversions for non-reference-related types.

Summary:
[expr.cast.static] states:
> 3. A glvalue of type “cv1 T1” can be cast to type “rvalue reference to cv2 T2” if “cv2 T2” is reference-compatible
> with “cv1 T1”. The result refers to the object or the specified base class subobject thereof. If T2 is
> an inaccessible or ambiguous base class of T1, a program that necessitates such a cast is
> ill-formed.
>
> 4. Otherwise, an expression e can be explicitly converted to a type T using a static_cast of the form static_-
> cast<T>(e) if the declaration T t(e); is well-formed, for some invented temporary variable t. [...]

Currently when checking p3 Clang will diagnose `static_cast<T&&>(e)` as invalid if the argument is not reference compatible with `T`. However I believe the correct behavior is to also check p4 in those cases.  For example:

```
double y = 42;
static_cast<int&&>(y); // this should be OK.  'int&& t(y)' is well formed
```

Note that we still don't check p4 for non-reference-compatible types which are reference-related since  `T&& t(e);` should never be well formed in those cases.

Reviewers: rsmith

Subscribers: cfe-commits

Differential Revision: https://reviews.llvm.org/D26231

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@285872 91177308-0d34-0410-b5e6-96231b3b80d8
include/clang/Basic/DiagnosticSemaKinds.td
lib/Sema/SemaCast.cpp
test/CXX/expr/expr.post/expr.static.cast/p3-p4-0x.cpp [new file with mode: 0644]
test/SemaCXX/rval-references.cpp