[PATCH] D39679: [C++11] Fix warning when dropping cv-qualifiers when assigning to a reference with a braced initializer list

Richard Smith - zygoloid via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Jan 4 15:42:10 PST 2018


rsmith added inline comments.


================
Comment at: lib/Sema/SemaInit.cpp:7691-7695
   case FK_RValueReferenceBindingToLValue:
     S.Diag(Kind.getLocation(), diag::err_lvalue_to_rvalue_ref)
       << DestType.getNonReferenceType() << Args[0]->getType()
       << Args[0]->getSourceRange();
     break;
----------------
Same problem exists here, and probably in a lot of these diagnostics. For example:

 *`int a; int &&b = {a};` says "cannot bind to lvalue of type 'void'")
 * `void f(int); void f() { int &&b = {f}; }` asserts due to not unwrapping the `InitListExpr` before trying to diagnose

Can you try to address this more generally? Perhaps: add an `Expr *OnlyArg`, which is null if `Args.size() != 1`, is the list element if `Args.size() == 1` and is an `InitListExpr` with a single element, and is otherwise `Args[0]`, and change all the diagnostics that are talking about a one-and-only argument to use `OnlyArg`?


https://reviews.llvm.org/D39679





More information about the cfe-commits mailing list