Fixes #201632. This patch fixes an assertion failure when code completion is triggered inside an ill-formed lambda's trailing requires-clause, as in ```cpp void f() { []() requires x /*invoke completion here*/ ``` https://godbolt.org/z/a66s7Y5cx When `tok::code_completion` is reached, parsing is cut off before the end of the declarator. This leaves the lambda's call operator without a type, thus triggering the `!isNull() && "Cannot retrieve a NULL type pointer"` assertion when `AddOrdinaryNameResults` calls `FunctionDecl::getReturnType()` later. Fix by guarding the `getReturnType()` call with a null check. Note: The crash stacktrace for the reproducer above differs slightly from #201632. Here, parsing is cut off during the parsing of the constraint expression. In #201632, parsing is cut off later during actual template parsing in `Parser::ParseTemplateIdAfterTemplateName`. Both leave the lambda without a `FunctionType`. Tests for both are included.
14 lines
453 B
C++
14 lines
453 B
C++
// RUN: not %clang_cc1 -std=c++20 -fsyntax-only -code-completion-at=%s:7:39 %s -DTEST_TEMPLATE
|
|
// RUN: not %clang_cc1 -std=c++20 -fsyntax-only -code-completion-at=%s:12:19 %s -DTEST_CONSTRAINT
|
|
|
|
#ifdef TEST_TEMPLATE
|
|
void template_cutoff() {
|
|
[=]() mutable -> decltype(y + x)
|
|
requires(is_same<decltype((y)), int /*invoke completion here*/ &>
|
|
#endif
|
|
|
|
#ifdef TEST_CONSTRAINT
|
|
void constraint_cutoff() {
|
|
[]() requires x /*invoke completion here*/
|
|
#endif
|