Skip to content

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'}}

@yronglin yronglin merged commit 513a646 into llvm:main Jul 16, 2025
12 checks passed
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