Skip to content

[NFC][clang] Refactor CXX/module/module.interface/p1.cpp with split-file #148861

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

yronglin
Copy link
Contributor

Refine CXX/module/module.interface/p1.cpp with split-file.
This MR is a part of #107168.

@llvmbot llvmbot added clang Clang issues not falling into any other category clang:modules C++20 modules and Clang Header Modules labels Jul 15, 2025
@llvmbot
Copy link
Member

llvmbot commented Jul 15, 2025

@llvm/pr-subscribers-clang

@llvm/pr-subscribers-clang-modules

Author: None (yronglin)

Changes

Refine CXX/module/module.interface/p1.cpp with split-file.
This MR is a part of #107168.


Full diff: https://github.com/llvm/llvm-project/pull/148861.diff

1 Files Affected:

  • (modified) clang/test/CXX/module/module.interface/p1.cpp (+24-18)
diff --git a/clang/test/CXX/module/module.interface/p1.cpp b/clang/test/CXX/module/module.interface/p1.cpp
index 54a201e502323..c3bfca930f5cc 100644
--- a/clang/test/CXX/module/module.interface/p1.cpp
+++ b/clang/test/CXX/module/module.interface/p1.cpp
@@ -1,28 +1,19 @@
-// RUN: %clang_cc1 -std=c++2a %s -DERRORS -verify
-// RUN: %clang_cc1 -std=c++2a %s -emit-module-interface -o %t.pcm
-// RUN: %clang_cc1 -std=c++2a %s -fmodule-file=M=%t.pcm -DIMPLEMENTATION -verify -Db=b2 -Dc=c2
+// RUN: rm -rf %t
+// RUN: split-file %s %t
 
-module;
+// RUN: %clang_cc1 -std=c++2a %t/errors.cpp -verify
+// RUN: %clang_cc1 -std=c++2a %t/M.cppm -emit-module-interface -o %t/M.pcm
+// RUN: %clang_cc1 -std=c++2a %t/impl.cpp -fmodule-file=M=%t/M.pcm -verify
 
-#ifdef ERRORS
+//--- errors.cpp
+module;
 export int a; // expected-error {{export declaration can only be used within a module purview}}
-#endif
-
-#ifndef IMPLEMENTATION
-export
-#else
-// expected-error@#1 {{export declaration can only be used within a module purview}}
-// expected-error@#2 {{export declaration can only be used within a module purview}}
-// expected-note@+2 1+{{add 'export'}}
-#endif
-module M;
-
+export module M;
 export int b; // #1
 namespace N {
   export int c; // #2
 }
 
-#ifdef ERRORS
 namespace { // expected-note 2{{anonymous namespace begins here}}
   export int d1; // expected-error {{export declaration appears within anonymous namespace}}
   namespace X {
@@ -35,4 +26,19 @@ export { export int f; } // expected-error {{within another export declaration}}
 
 module :private; // expected-note {{private module fragment begins here}}
 export int priv; // expected-error {{export declaration cannot be used in a private module fragment}}
-#endif
+
+//--- M.cppm
+export module M;
+export int b;
+namespace N {
+  export int c;
+}
+
+//--- impl.cpp
+module M; // #M
+
+export int b2; // expected-error {{export declaration can only be used within a module purview}}
+namespace N {
+  export int c2; // expected-error {{export declaration can only be used within a module purview}}
+}
+// expected-note@#M 2+{{add 'export'}}

//--- impl.cpp
module M; // #M

export int b2; // expected-error {{export declaration can only be used within a module purview}}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know this commit is just moving stuff around, but I wanted to note that this diagnostic is incorrectly worded. This line is in a module purview (https://eel.is/c++draft/module#unit-5). This should say "within the purview of a module interface" for this case, or just "within a module interface" to be less pedantic.

No need to fix this here though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:modules C++20 modules and Clang Header Modules clang Clang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants