[PATCH] D113837: Sema: Let InitListExpr have dependent type instead of 'void'

Aaron Puchert via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Sat Nov 13 16:18:58 PST 2021


aaronpuchert created this revision.
aaronpuchert added a reviewer: rsmith.
aaronpuchert requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

It was always just a placeholder, but not a particularly good one: the
expression certainly has a value in most cases, and 'void' can also not
serve as an indicator for an undeduced type because of void{}.

Instead I think the dependent type is a good fit: an initializer list
is an expression that can instantiate to expressions of arbitrary types:
One could say that {...} is a map

  T : Type → T, T ↦ T{...}

The type parameter can be explicitly specified or be deduced from an
implicit conversion target type. So one could for example view {1} as

  struct InitList1 {
    template<typename T>
    operator T() { return T{1}; }
  };

That in itself isn't type-dependent, but note that we let InitListExprs
have the actual type they initialize in the end, so in this case 'T'
instead of 'InitList1'.

A test failure in CXX/expr/expr.prim/expr.prim.lambda/p4.cpp revealed
that we were emitting errors "return type ... must match previous
return type ... when lambda expression has unspecified explicit return
type" even after diagnosing InitListExprs with "cannot deduce lambda
return type from initializer list", which in this case didn't show up
because it accidentally matched with the actual 'void' of the other
return statements.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D113837

Files:
  clang/include/clang/AST/Expr.h
  clang/lib/Sema/SemaExpr.cpp
  clang/lib/Sema/SemaInit.cpp
  clang/lib/Sema/SemaLambda.cpp
  clang/test/AST/ast-dump-decl.cpp
  clang/test/AST/ast-dump-recovery.cpp
  clang/test/AST/ast-dump-stmt-json.cpp
  clang/test/SemaOpenCLCXX/address-space-references.clcpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D113837.387051.patch
Type: text/x-patch
Size: 5832 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20211114/0a6267cd/attachment.bin>


More information about the cfe-commits mailing list