Skip to content

Commit 65780f4

Browse files
authored
[C++20][Modules] Allow import for a header unit after #pragma (#111662)
Summary: `#pragma` and headers that finish with them shouldn't prevent `import "header_unit.h"` syntax. Test Plan: check-clang
1 parent 173c682 commit 65780f4

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

clang/lib/Lex/Preprocessor.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -902,6 +902,10 @@ void Preprocessor::Lex(Token &Result) {
902902
case tok::r_brace:
903903
StdCXXImportSeqState.handleCloseBrace();
904904
break;
905+
#define PRAGMA_ANNOTATION(X) case tok::annot_##X:
906+
// For `#pragma ...` mimic ';'.
907+
#include "clang/Basic/TokenKinds.def"
908+
#undef PRAGMA_ANNOTATION
905909
// This token is injected to represent the translation of '#include "a.h"'
906910
// into "import a.h;". Mimic the notional ';'.
907911
case tok::annot_module_include:
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// RUN: rm -fR %t
2+
// RUN: split-file %s %t
3+
// RUN: cd %t
4+
// RUN: %clang_cc1 -verify -std=c++20 -emit-header-unit -xc++-user-header bz0.h
5+
// RUN: %clang_cc1 -verify -std=c++20 -emit-header-unit -xc++-user-header -fmodule-file=bz0.pcm bz.cpp
6+
7+
//--- compare
8+
#pragma GCC visibility push(default)
9+
#pragma GCC visibility pop
10+
11+
//--- bz0.h
12+
#include "compare"
13+
// expected-no-diagnostics
14+
15+
//--- bz.cpp
16+
#include "compare"
17+
18+
import "bz0.h"; // expected-warning {{the implementation of header units is in an experimental phase}}

0 commit comments

Comments
 (0)