[clang] 4050d7a - [clang] Fix assertion failures involving code completion with delayed default arguments and exception specifications (#203794)
via cfe-commits
cfe-commits at lists.llvm.org
Sun Jun 28 17:44:27 PDT 2026
Author: Harlen Batagelo
Date: 2026-06-29T08:44:22+08:00
New Revision: 4050d7a96903eec615c57e1d3d6f3c824096244c
URL: https://github.com/llvm/llvm-project/commit/4050d7a96903eec615c57e1d3d6f3c824096244c
DIFF: https://github.com/llvm/llvm-project/commit/4050d7a96903eec615c57e1d3d6f3c824096244c.diff
LOG: [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.
Added:
clang/test/CodeCompletion/GH200879.cpp
Modified:
clang/docs/ReleaseNotes.rst
clang/lib/Parse/ParseCXXInlineMethods.cpp
Removed:
################################################################################
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index d6b978ec91659..4337b20e59070 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -744,6 +744,7 @@ Bug Fixes in This Version
- Fixed crash when checking for overflow for unary operator that can't overflow (#GH170072)
- Clang no longer handles a `" q-char-sequence "` header name as a string literal (#GH132643).
- Fixed an assertion where we improperly handled implicit conversions to integral types from an atomic-type with a conversion function. (#GH201770)
+- Fixed assertion failures involving code completion with delayed default arguments and exception specifications. (#GH200879)
- Fixed a regression where calling a function that takes a class-type parameter by value inside ``decltype`` of a concept could be incorrectly rejected when used as a non-type template argument. (#GH175831)
Bug Fixes to Compiler Builtins
diff --git a/clang/lib/Parse/ParseCXXInlineMethods.cpp b/clang/lib/Parse/ParseCXXInlineMethods.cpp
index d13f73641218b..9949adf199fd2 100644
--- a/clang/lib/Parse/ParseCXXInlineMethods.cpp
+++ b/clang/lib/Parse/ParseCXXInlineMethods.cpp
@@ -421,7 +421,7 @@ void Parser::ParseLexedMethodDeclaration(LateParsedMethodDeclaration &LM) {
PP.EnterTokenStream(*Toks, true, /*IsReinject*/ true);
// Consume the previously-pushed token.
- ConsumeAnyToken();
+ ConsumeAnyToken(/*ConsumeCodeCompletionTok=*/true);
// Consume the '='.
assert(Tok.is(tok::equal) && "Default argument not starting with '='");
@@ -501,7 +501,7 @@ void Parser::ParseLexedMethodDeclaration(LateParsedMethodDeclaration &LM) {
PP.EnterTokenStream(*Toks, true, /*IsReinject*/true);
// Consume the previously-pushed token.
- ConsumeAnyToken();
+ ConsumeAnyToken(/*ConsumeCodeCompletionTok=*/true);
// C++11 [expr.prim.general]p3:
// If a declaration declares a member function or member function
diff --git a/clang/test/CodeCompletion/GH200879.cpp b/clang/test/CodeCompletion/GH200879.cpp
new file mode 100644
index 0000000000000..742b02456ede6
--- /dev/null
+++ b/clang/test/CodeCompletion/GH200879.cpp
@@ -0,0 +1,10 @@
+// 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*/;
More information about the cfe-commits
mailing list