Skip to content

Commit

Permalink
Fix unexpected compiler error when code complete in export mod^.
Browse files Browse the repository at this point in the history
  • Loading branch information
16bit-ykiko committed Oct 12, 2024
1 parent 15f6982 commit b6218b6
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
2 changes: 2 additions & 0 deletions .clangd
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
CompileFlags:
Add: [-std=c++20]
12 changes: 12 additions & 0 deletions clang/lib/Parse/ParseDeclCXX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,18 @@ Decl *Parser::ParseExportDeclaration() {
assert(Tok.is(tok::kw_export));
SourceLocation ExportLoc = ConsumeToken();

if (Tok.is(tok::code_completion)) {
cutOffParsing();
SemaCodeCompletion::ParserCompletionContext PCC;
if (PP.isIncrementalProcessingEnabled()) {
PCC = SemaCodeCompletion::PCC_TopLevelOrExpression;
} else {
PCC = SemaCodeCompletion::PCC_Namespace;
};
Actions.CodeCompletion().CodeCompleteOrdinaryName(getCurScope(), PCC);
return nullptr;
}

ParseScope ExportScope(this, Scope::DeclScope);
Decl *ExportDecl = Actions.ActOnStartExportDecl(
getCurScope(), ExportLoc,
Expand Down
9 changes: 6 additions & 3 deletions clang/test/CodeCompletion/keywords-cxx20.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module;

export module M;

const char8_t x = 1;
export const char8_t x = 1;

template<typename T> requires true
const int y = requires { typename T::type; requires T::value; };
Expand All @@ -17,19 +17,22 @@ module: private;
// CHECK-MODULE1: module;
// CHECK-MODULE1: module <#name#>;

// RUN: %clang_cc1 -std=c++20 -code-completion-at=%s:3:11 %s | FileCheck --check-prefix=CHECK-MODULE2 %s
// CHECK-MODULE2: module <#name#>;

// RUN: %clang_cc1 -std=c++20 -code-completion-at=%s:14:3 %s | FileCheck --check-prefix=CHECK-MODULE3 %s
// CHECK-MODULE3: module: private;

// RUN: %clang_cc1 -std=c++20 -code-completion-at=%s:3:3 %s | FileCheck --check-prefix=CHECK-EXPORT %s
// CHECK-EXPORT: export

// RUN: %clang_cc1 -std=c++20 -code-completion-at=%s:5:3 %s | FileCheck --check-prefix=CHECK-CONST %s
// RUN: %clang_cc1 -std=c++20 -code-completion-at=%s:5:11 %s | FileCheck --check-prefix=CHECK-CONST %s
// CHECK-CONST: const
// CHECK-CONST: consteval
// CHECK-CONST: constexpr
// CHECK-CONST: constinit

// RUN: %clang_cc1 -std=c++20 -code-completion-at=%s:5:12 %s | FileCheck --check-prefix=CHECK-CHAR %s
// RUN: %clang_cc1 -std=c++20 -code-completion-at=%s:5:19 %s | FileCheck --check-prefix=CHECK-CHAR %s
// CHECK-CHAR: char8_t

// RUN: %clang_cc1 -std=c++20 -code-completion-at=%s:8:3 %s | FileCheck --check-prefix=CHECK-CONSTRAINT %s
Expand Down

0 comments on commit b6218b6

Please sign in to comment.