[cfe-commits] r151551 - in /cfe/trunk: lib/Sema/SemaExpr.cpp test/CXX/expr/expr.ass/p9-cxx11.cpp
Sebastian Redl
sebastian.redl at getdesigned.at
Mon Feb 27 12:34:02 PST 2012
Author: cornedbee
Date: Mon Feb 27 14:34:02 2012
New Revision: 151551
URL: http://llvm.org/viewvc/llvm-project?rev=151551&view=rev
Log:
Convert initializer lists to temporaries in CreateBuiltinBinOp. Allows assignment of init lists to built-in types and resolves PR12088.
Modified:
cfe/trunk/lib/Sema/SemaExpr.cpp
cfe/trunk/test/CXX/expr/expr.ass/p9-cxx11.cpp
Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=151551&r1=151550&r2=151551&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Mon Feb 27 14:34:02 2012
@@ -7612,6 +7612,25 @@
ExprResult Sema::CreateBuiltinBinOp(SourceLocation OpLoc,
BinaryOperatorKind Opc,
Expr *LHSExpr, Expr *RHSExpr) {
+ if (getLangOptions().CPlusPlus0x && isa<InitListExpr>(RHSExpr)) {
+ // The syntax only allows initializer lists on the RHS of assignment,
+ // so we don't need to worry about accepting invalid code for
+ // non-assignment operators.
+ // C++11 5.17p9:
+ // The meaning of x = {v} [...] is that of x = T(v) [...]. The meaning
+ // of x = {} is x = T().
+ InitializationKind Kind =
+ InitializationKind::CreateDirectList(RHSExpr->getLocStart());
+ InitializedEntity Entity =
+ InitializedEntity::InitializeTemporary(LHSExpr->getType());
+ InitializationSequence InitSeq(*this, Entity, Kind, &RHSExpr, 1);
+ ExprResult Init = InitSeq.Perform(*this, Entity, Kind,
+ MultiExprArg(&RHSExpr, 1));
+ if (Init.isInvalid())
+ return Init;
+ RHSExpr = Init.take();
+ }
+
ExprResult LHS = Owned(LHSExpr), RHS = Owned(RHSExpr);
QualType ResultTy; // Result type of the binary operator.
// The following two variables are used for compound assignment operators
Modified: cfe/trunk/test/CXX/expr/expr.ass/p9-cxx11.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/expr/expr.ass/p9-cxx11.cpp?rev=151551&r1=151550&r2=151551&view=diff
==============================================================================
--- cfe/trunk/test/CXX/expr/expr.ass/p9-cxx11.cpp (original)
+++ cfe/trunk/test/CXX/expr/expr.ass/p9-cxx11.cpp Mon Feb 27 14:34:02 2012
@@ -11,10 +11,9 @@
z = { 1, 2 };
z += { 1, 2 };
- // FIXME: implement semantics of scalar init list assignment.
int a, b;
- a = b = { 1 }; // unexpected-error {{incompatible type 'void'}}
- a = { 1 } = b; // unexpected-error {{incompatible type 'void'}}
+ a = b = { 1 };
+ a = { 1 } = b;
}
struct S {
More information about the cfe-commits
mailing list