r335779 - DR1213: Ignore implicit conversions when determining if an operand of an
Richard Smith via cfe-commits
cfe-commits at lists.llvm.org
Wed Jun 27 13:29:32 PDT 2018
Author: rsmith
Date: Wed Jun 27 13:29:32 2018
New Revision: 335779
URL: http://llvm.org/viewvc/llvm-project?rev=335779&view=rev
Log:
DR1213: Ignore implicit conversions when determining if an operand of an
array subscript expression is an array prvalue.
Also apply DR1213 to vector prvalues for consistency.
Modified:
cfe/trunk/lib/Sema/SemaExpr.cpp
cfe/trunk/test/CXX/drs/dr12xx.cpp
Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=335779&r1=335778&r2=335779&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Wed Jun 27 13:29:32 2018
@@ -4385,10 +4385,13 @@ Sema::CreateBuiltinArraySubscriptExpr(Ex
// Per C++ core issue 1213, the result is an xvalue if either operand is
// a non-lvalue array, and an lvalue otherwise.
- if (getLangOpts().CPlusPlus11 &&
- ((LHSExp->getType()->isArrayType() && !LHSExp->isLValue()) ||
- (RHSExp->getType()->isArrayType() && !RHSExp->isLValue())))
- VK = VK_XValue;
+ if (getLangOpts().CPlusPlus11) {
+ for (auto *Op : {LHSExp, RHSExp}) {
+ Op = Op->IgnoreImplicit();
+ if (Op->getType()->isArrayType() && !Op->isLValue())
+ VK = VK_XValue;
+ }
+ }
// Perform default conversions.
if (!LHSExp->getType()->getAs<VectorType>()) {
@@ -4449,6 +4452,13 @@ Sema::CreateBuiltinArraySubscriptExpr(Ex
} else if (const VectorType *VTy = LHSTy->getAs<VectorType>()) {
BaseExpr = LHSExp; // vectors: V[123]
IndexExpr = RHSExp;
+ // We apply C++ DR1213 to vector subscripting too.
+ if (getLangOpts().CPlusPlus11 && LHSExp->getValueKind() == VK_RValue) {
+ ExprResult Materialized = TemporaryMaterializationConversion(LHSExp);
+ if (Materialized.isInvalid())
+ return ExprError();
+ LHSExp = Materialized.get();
+ }
VK = LHSExp->getValueKind();
if (VK != VK_RValue)
OK = OK_VectorComponent;
Modified: cfe/trunk/test/CXX/drs/dr12xx.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/drs/dr12xx.cpp?rev=335779&r1=335778&r2=335779&view=diff
==============================================================================
--- cfe/trunk/test/CXX/drs/dr12xx.cpp (original)
+++ cfe/trunk/test/CXX/drs/dr12xx.cpp Wed Jun 27 13:29:32 2018
@@ -3,7 +3,7 @@
// RUN: %clang_cc1 -std=c++14 %s -verify -fexceptions -fcxx-exceptions -pedantic-errors
// RUN: %clang_cc1 -std=c++1z %s -verify -fexceptions -fcxx-exceptions -pedantic-errors
-namespace dr1213 { // dr1213: 4
+namespace dr1213 { // dr1213: 7
#if __cplusplus >= 201103L
using T = int[3];
int &&r = T{}[1];
@@ -11,6 +11,19 @@ namespace dr1213 { // dr1213: 4
using T = decltype((T{}));
using U = decltype((T{}[2]));
using U = int &&;
+
+ // Same thing but in a case where we consider overloaded operator[].
+ struct ConvertsToInt {
+ operator int();
+ };
+ struct X { int array[1]; };
+ using U = decltype(X().array[ConvertsToInt()]);
+
+ // We apply the same rule to vector subscripting.
+ typedef int V4Int __attribute__((__vector_size__(sizeof(int) * 4)));
+ typedef int EV4Int __attribute__((__ext_vector_type__(4)));
+ using U = decltype(V4Int()[0]);
+ using U = decltype(EV4Int()[0]);
#endif
}
More information about the cfe-commits
mailing list