llvm-project/clang/test/CXX/expr/expr.prim/expr.prim.lambda
Tom Honermann 4409a83c29 [clang] Correct handling of lambdas in lambda default arguments in dependent contexts.
Previously, a lambda expression in a dependent context with a default argument
containing an immediately invoked lambda expression would produce a closure
class object that, if invoked such that the default argument was used, resulted
in a compiler crash or one of the following assertion failures during code
generation. The failures occurred regardless of whether the lambda expressions
were dependent.

  clang/lib/CodeGen/CGCall.cpp:
  Assertion `(isGenericMethod || Ty->isVariablyModifiedType() || Ty.getNonReferenceType()->isObjCRetainableType() || getContext() .getCanonicalType(Ty.getNonReferenceType()) .getTypePtr() == getContext().getCanonicalType((*Arg)->getType()).getTypePtr()) && "type mismatch in call argument!"' failed.

  clang/lib/AST/Decl.cpp:
  Assertion `!Init->isValueDependent()' failed.

Default arguments in declarations in local context are instantiated along with
their enclosing function or variable template (since such declarations can't
be explicitly specialized). Previously, such instantiations were performed at
the same time that their associated parameters were instantiated. However, that
approach fails in cases like the following in which the context for the inner
lambda is the outer lambda, but construction of the outer lambda is dependent
on the parameters of the inner lambda. This change resolves this dependency by
delyaing instantiation of default arguments in local contexts until after
construction of the enclosing context.
  template <typename T>
  auto f() {
    return [](T = []{ return T{}; }()) { return 0; };
  }

Refactoring included with this change results in the same code now being used
to instantiate default arguments that appear in local context and those that
are only instantiated when used at a call site; previously, such code was
duplicated and out of sync.

Fixes https://github.com/llvm/llvm-project/issues/49178

Reviewed By: erichkeane

Differential Revision: https://reviews.llvm.org/D133500
2022-10-04 09:04:54 -07:00
..
expr.prim.lambda.capture
expr.prim.lambda.closure
blocks-irgen.mm [OpaquePtrs][Clang] Add -no-opaque-pointers to tests (NFC) 2022-04-07 12:09:47 +02:00
blocks.mm
default-arguments.cpp [clang] Correct handling of lambdas in lambda default arguments in dependent contexts. 2022-10-04 09:04:54 -07:00
p2-generic-lambda-1y.cpp [Sema] Add some basic lambda capture fix-its 2021-03-11 13:46:25 +00:00
p2-template-parameter.cpp
p2.cpp
p3.cpp
p4-cxx14.cpp [clang] NFC: include non friendly types and missing sugar in test expectations 2021-10-27 23:03:29 +02:00
p4.cpp Revert D119136 "[clang] Implement Change scope of lambda trailing-return-type" and its follow-up 2022-04-20 10:57:12 -07:00
p4.mm
p5-generic-lambda-1y.cpp
p5.cpp
p6.cpp
p7.cpp
p8.cpp
p9.cpp
p10.cpp
p11-1y.cpp Revert D119136 "[clang] Implement Change scope of lambda trailing-return-type" and its follow-up 2022-04-20 10:57:12 -07:00
p11.cpp
p12.cpp [Clang] -Wunused-but-set-parameter and -Wunused-but-set-variable 2021-06-01 15:38:48 -07:00
p13.cpp
p14.cpp [clang] Implement ElaboratedType sugaring for types written bare 2022-07-27 11:10:54 +02:00
p15-star-this-capture.cpp
p15.cpp
p16.cpp
p18.cpp
p19.cpp
p20.cpp
p21.cpp
p23.cpp
templates.cpp