[clang] [NFC][C++][Modules] Refine basic.link.p3 and add test for P2788R0 (PR #147945)
via cfe-commits
cfe-commits at lists.llvm.org
Thu Jul 10 05:39:13 PDT 2025
================
@@ -51,4 +39,71 @@ template<typename T> module module_var_template;
// This is a variable named 'import' that shadows the type 'import' above.
struct X {} import;
-#endif
+
+//--- ImportError1.cppm
+module;
+
+struct import { struct inner {}; };
+struct module { struct inner {}; };
+
+constexpr int n = 123;
+
+export module m; // #1
+
+import x = {}; // expected-error {{expected ';' after module name}}
+ // expected-error at -1 {{module 'x' not found}}
+
+//--- ImportError2.cppm
+module;
+
+struct module { struct inner {}; };
+
+constexpr int n = 123;
+
+export module m; // #1
+
+struct X;
+template<int> struct import;
+template<> struct import<n> {
+ static X y;
+};
+
+// This is not valid because the 'import <n>' is a pp-import, even though it
+// grammatically can't possibly be an import declaration.
+struct X {} import<n>::y; // expected-error {{'n' file not found}}
+
+//--- A.cppm
+export module A;
+const double delta=0.01;
+export {
+ template<class F>
+ double derivative(F &&f,double x) {
+ return (f(x+delta)-f(x))/delta;
+ }
+}
+
+//--- std.cppm
+export module std;
+export using size_t = decltype(sizeof(void *));
+
+export namespace std {
+ template <typename T, size_t N>
+ struct array {};
+}
+
+//--- A-B.cppm
+module A:B;
+const int dimensions=3;
----------------
yronglin wrote:
Do we need to add tests in basic.link/p3.cpp? or just covered in SemaCXX is enough.
https://github.com/llvm/llvm-project/pull/147945
More information about the cfe-commits
mailing list