Author: Dmitry Polukhin Date: 2024-10-11T08:23:35+01:00 New Revision: 65780f4d8e34461e6bd3baf2ff77496f97874b94
URL: https://github.com/llvm/llvm-project/commit/65780f4d8e34461e6bd3baf2ff77496f97874b94 DIFF: https://github.com/llvm/llvm-project/commit/65780f4d8e34461e6bd3baf2ff77496f97874b94.diff LOG: [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 Added: clang/test/Headers/import_header_unit_after_pragma.cpp Modified: clang/lib/Lex/Preprocessor.cpp Removed: ################################################################################ diff --git a/clang/lib/Lex/Preprocessor.cpp b/clang/lib/Lex/Preprocessor.cpp index f0b4593e0cc22e..ecc5166d7b814c 100644 --- a/clang/lib/Lex/Preprocessor.cpp +++ b/clang/lib/Lex/Preprocessor.cpp @@ -902,6 +902,10 @@ void Preprocessor::Lex(Token &Result) { case tok::r_brace: StdCXXImportSeqState.handleCloseBrace(); break; +#define PRAGMA_ANNOTATION(X) case tok::annot_##X: +// For `#pragma ...` mimic ';'. +#include "clang/Basic/TokenKinds.def" +#undef PRAGMA_ANNOTATION // This token is injected to represent the translation of '#include "a.h"' // into "import a.h;". Mimic the notional ';'. case tok::annot_module_include: diff --git a/clang/test/Headers/import_header_unit_after_pragma.cpp b/clang/test/Headers/import_header_unit_after_pragma.cpp new file mode 100644 index 00000000000000..b1ad3b07fea29c --- /dev/null +++ b/clang/test/Headers/import_header_unit_after_pragma.cpp @@ -0,0 +1,18 @@ +// RUN: rm -fR %t +// RUN: split-file %s %t +// RUN: cd %t +// RUN: %clang_cc1 -verify -std=c++20 -emit-header-unit -xc++-user-header bz0.h +// RUN: %clang_cc1 -verify -std=c++20 -emit-header-unit -xc++-user-header -fmodule-file=bz0.pcm bz.cpp + +//--- compare +#pragma GCC visibility push(default) +#pragma GCC visibility pop + +//--- bz0.h +#include "compare" +// expected-no-diagnostics + +//--- bz.cpp +#include "compare" + +import "bz0.h"; // expected-warning {{the implementation of header units is in an experimental phase}} _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits