Files
Harlen Batagelo 4050d7a969 [clang] Fix assertion failures involving code completion with delayed default arguments and exception specifications (#203794)
Fixes #200879.

This patch fixes crashes when code completion is invoked immediately
after the declaration of a top-level class containing methods with
default arguments or exception specifications.

Default-argument case: https://godbolt.org/z/4G9nTfnGd
Exception-specification case: https://godbolt.org/z/8frEv8von

When code completion is triggered right after the class body, the
lookahead token is `tok::code_completion` when late parsing begins. The
token is saved to the cached token stream and `ConsumeAnyToken()` is
called to consume it, but `ConsumeAnyToken()` defaults to rejecting
completion tokens, which cuts off parsing. In the default-arguments path
(as reported in #200879), the assertion `Tok.is(tok::equal) && "Default
argument not starting with '='"` is triggered because `cutOffParsing()`
sets the current token to `eof`.

Fix by using `ConsumeAnyToken(/*ConsumeCodeCompletionTok=*/true)` when
consuming the pushed token.
2026-06-29 08:44:22 +08:00

11 lines
246 B
C++

// RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:6:2 %s
// RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:10:2 %s
struct A {
A(int = 0);
}/*invoke completion here*/;
struct B {
B() noexcept(false);
}/*invoke completion here*/;