mirror-llvm-project/clang/test/CodeCompletion
Harlen Batagelo a7ee75a807
[clang] Fix code completion crash in lambda trailing requires-clause (#206373)
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.
2026-07-01 07:42:06 -04:00
..
Inputs
accessibility-crash.cpp
accessibility.cpp
after-function-equals.cpp
attr.cpp
auto.cpp
auto_type.c
bracket-decl.c
call.c
call.cpp
comments.cpp
concepts.cpp
constexpr.cpp
cpp23-explicit-object.cpp [clangd] Code completion for declaration of class method (#165916) 2026-03-22 22:25:54 +00:00
crash-func-decl.cpp
crash-func-init.cpp
crash-if-directive.cpp
crash-null-type.cpp
crash-skipped-bodies-template-inst.cpp
ctor-initializer.cpp
ctor-signature.cpp
desig-init.cpp [clang] Complete fields in __builtin_offsetof designators (#195126) 2026-05-21 14:03:36 +03:00
deuglify.cpp
documentation.cpp
documentation.m
enable-if-attr-crash.cpp
end-of-file.cpp
end-of-ident-macro.cpp
end-of-ident.cpp
enum-preferred-type.cpp
enum-switch-case-qualified.cpp
enum-switch-case.c
enum-switch-case.cpp
function-overloads.cpp
function-templates.cpp
functions.cpp
GH125500.cpp [clang] Fix CodeComplete crash involving CWG1432 (#129436) 2025-03-03 11:41:50 -03:00
GH139019.cpp [clang] Serialization: support hashing null template arguments (#141890) 2025-05-29 02:08:11 -03:00
GH200879.cpp [clang] Fix assertion failures involving code completion with delayed default arguments and exception specifications (#203794) 2026-06-29 08:44:22 +08:00
GH201632.cpp [clang] Fix code completion crash in lambda trailing requires-clause (#206373) 2026-07-01 07:42:06 -04:00
if-const.cpp [clang][CodeComplete] Add code completion for if constexpr and consteval (#124315) 2025-03-17 02:45:19 -04:00
ignore-ns-level-decls.cpp
included-files.cpp [CodeCompletion] Consider header files without extension, if... (#166447) 2026-02-23 10:02:03 +01:00
included-frameworks.m
included-symlinks.cpp [clang] Remove shell requirements from tests 2025-09-11 17:51:47 -07:00
incomplete-member.cpp
incomplete-ret-type.cpp
incrememal-mode-completion-no-error.cpp
incremental-top-level.cpp
inside-macros.cpp
invalid-initialized-class.cpp
keywords-cxx20.cpp
keywords.cpp
lambdas.cpp
macros-in-modules.c
macros-in-modules.m
macros.c
member-access-qualifiers.cpp
member-access.c [CodeComplete] Don't drop ArrayToPointerDecay when doing member completion (#134951) 2025-04-15 10:12:18 -07:00
member-access.cpp [clangd] Code completion for declaration of class method (#165916) 2026-03-22 22:25:54 +00:00
namespace-alias.cpp
namespace.cpp
nested-name-specifier.cpp
objc-cast-parenthesized-expr.m [clang][ObjC][CodeComplete] Fix crash on C-Style cast with parenthesized operand in ObjC++ (#180343) 2026-02-15 15:30:03 -08:00
objc-expr.m
objc-member-access.m
objc-message.m
objc-message.mm
objc-protocol-member-access.m
offsetof.cpp [clang] Complete fields in __builtin_offsetof designators (#195126) 2026-05-21 14:03:36 +03:00
operator.cpp
ordinary-name-cxx11.cpp
ordinary-name.c
ordinary-name.cpp
overrides.cpp [Sema][clangd] add noexcept to override functions during code completion (#75937) 2025-06-28 14:37:20 +08:00
paren_locs.cpp
patterns.cpp
pch-and-module.m
PR9728.cpp
pragma-macro-token-caching.c
preamble.c
preferred-type.cpp
qualifiers-as-written.cpp
self-inits.cpp
signatures-crash.cpp
skip-auto-funcs.cpp
some_struct.h
source-loc-zero.cpp [clang] Enforce 1-based indexing for command line source locations (#139457) 2025-05-15 09:36:28 -04:00
stdin.c
tag.c
tag.cpp
template-signature.cpp
templates.cpp
this-quals.cpp
truncation.c
truncation.c.h
uninstantiated_params.cpp
using-enum.cpp
using-namespace.cpp
using.cpp
variadic-template.cpp