diff options
author | Sebastian Redl <sebastian.redl@getdesigned.at> | 2012-02-27 20:34:02 +0000 |
---|---|---|
committer | Sebastian Redl <sebastian.redl@getdesigned.at> | 2012-02-27 20:34:02 +0000 |
commit | 6776673f099d3610e86440d253fef1f3ae64323f (patch) | |
tree | 6ff17f5104c0a0b4f9a85456421eb45d242d2e2a | |
parent | e932a685758222040a6ca37ec1d7e5cf157e55fe (diff) | |
download | bcm5719-llvm-6776673f099d3610e86440d253fef1f3ae64323f.tar.gz bcm5719-llvm-6776673f099d3610e86440d253fef1f3ae64323f.zip |
Convert initializer lists to temporaries in CreateBuiltinBinOp. Allows assignment of init lists to built-in types and resolves PR12088.
llvm-svn: 151551
-rw-r--r-- | clang/lib/Sema/SemaExpr.cpp | 19 | ||||
-rw-r--r-- | clang/test/CXX/expr/expr.ass/p9-cxx11.cpp | 5 |
2 files changed, 21 insertions, 3 deletions
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp index 10ae8f4badb..30a02b29539 100644 --- a/clang/lib/Sema/SemaExpr.cpp +++ b/clang/lib/Sema/SemaExpr.cpp @@ -7612,6 +7612,25 @@ static void DiagnoseSelfAssignment(Sema &S, Expr *LHSExpr, Expr *RHSExpr, 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 diff --git a/clang/test/CXX/expr/expr.ass/p9-cxx11.cpp b/clang/test/CXX/expr/expr.ass/p9-cxx11.cpp index fcef97cde5b..bd1603d6ab6 100644 --- a/clang/test/CXX/expr/expr.ass/p9-cxx11.cpp +++ b/clang/test/CXX/expr/expr.ass/p9-cxx11.cpp @@ -11,10 +11,9 @@ void std_example() { 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 { |