[clang] [Clang] Initializer list on RHS of assignment (PR #100548)
via cfe-commits
cfe-commits at lists.llvm.org
Thu Jul 25 06:48:34 PDT 2024
================
@@ -14578,21 +14578,56 @@ ExprResult Sema::CreateBuiltinBinOp(SourceLocation OpLoc,
BinaryOperatorKind Opc,
Expr *LHSExpr, Expr *RHSExpr) {
if (getLangOpts().CPlusPlus11 && 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->getBeginLoc(), RHSExpr->getBeginLoc(), RHSExpr->getEndLoc());
- InitializedEntity Entity =
- InitializedEntity::InitializeTemporary(LHSExpr->getType());
- InitializationSequence InitSeq(*this, Entity, Kind, RHSExpr);
- ExprResult Init = InitSeq.Perform(*this, Entity, Kind, RHSExpr);
- if (Init.isInvalid())
- return Init;
- RHSExpr = Init.get();
+ // C++11 [expr.ass]p9, per CWG2768:
+ // A braced-init-list B may appear on the right-hand side of
+ // - an assignment to a scalar of type T, in which case the initializer
+ // list shall have at most a single element. The meaning of x = B is
+ // x = t, where t is an invented temporary variable declared and
+ // initialized as T t = B.
+ switch (Opc) {
----------------
cor3ntin wrote:
Using a switch here is not ideal.
There are only 3 cases we care about
- BO_Assign
- isAssignmentOp
- everything else
https://github.com/llvm/llvm-project/pull/100548
More information about the cfe-commits
mailing list