xref: /llvm-project/clang/test/CXX/module/module.interface/p2-2.cpp (revision a0d266d705d6c145e8daa08a08f70e9498ec3d0b)
13a3af2bbSChuanqi Xu // The intention of this file to check we could only export declarations in namesapce scope.
23a3af2bbSChuanqi Xu //
33a3af2bbSChuanqi Xu // RUN: %clang_cc1 -std=c++20 %s -verify
43a3af2bbSChuanqi Xu 
53a3af2bbSChuanqi Xu export module X;
63a3af2bbSChuanqi Xu 
73a3af2bbSChuanqi Xu export template <typename T>
83a3af2bbSChuanqi Xu struct X {
93a3af2bbSChuanqi Xu   struct iterator {
103a3af2bbSChuanqi Xu     T node;
113a3af2bbSChuanqi Xu   };
fooX123a3af2bbSChuanqi Xu   void foo() {}
133a3af2bbSChuanqi Xu   template <typename U>
143a3af2bbSChuanqi Xu   U bar();
153a3af2bbSChuanqi Xu };
163a3af2bbSChuanqi Xu 
176f2b3478SAlan Zhao export template <typename T> struct X<T>::iterator;               // expected-error {{cannot export 'iterator' as it is not at namespace scope}}
18*a0d266d7SKrystian Stasiowski                                                                   // expected-error@-1 {{forward declaration of struct cannot have a nested name specifier}}
193a3af2bbSChuanqi Xu export template <typename T> void X<T>::foo();                    // expected-error {{cannot export 'foo' as it is not at namespace scope}}
203a3af2bbSChuanqi Xu export template <typename T> template <typename U> U X<T>::bar(); // expected-error {{cannot export 'bar' as it is not at namespace scope}}
213a3af2bbSChuanqi Xu 
223a3af2bbSChuanqi Xu export struct Y {
233a3af2bbSChuanqi Xu   struct iterator {
243a3af2bbSChuanqi Xu     int node;
253a3af2bbSChuanqi Xu   };
fooY263a3af2bbSChuanqi Xu   void foo() {}
273a3af2bbSChuanqi Xu   template <typename U>
283a3af2bbSChuanqi Xu   U bar();
293a3af2bbSChuanqi Xu };
303a3af2bbSChuanqi Xu 
313a3af2bbSChuanqi Xu export struct Y::iterator;               // expected-error {{cannot export 'iterator' as it is not at namespace scope}}
32*a0d266d7SKrystian Stasiowski                                          // expected-error@-1 {{forward declaration of struct cannot have a nested name specifier}}
333a3af2bbSChuanqi Xu export void Y::foo();                    // expected-error {{cannot export 'foo' as it is not at namespace scope}}
343a3af2bbSChuanqi Xu export template <typename U> U Y::bar(); // expected-error {{cannot export 'bar' as it is not at namespace scope}}
353a3af2bbSChuanqi Xu 
363a3af2bbSChuanqi Xu export {
376f2b3478SAlan Zhao   template <typename T> struct X<T>::iterator; // expected-error {{cannot export 'iterator' as it is not at namespace scope}}
38*a0d266d7SKrystian Stasiowski                                                // expected-error@-1 {{forward declaration of struct cannot have a nested name specifier}}
393a3af2bbSChuanqi Xu   struct Y::iterator;                          // expected-error {{cannot export 'iterator' as it is not at namespace scope}}
40*a0d266d7SKrystian Stasiowski                                                // expected-error@-1 {{forward declaration of struct cannot have a nested name specifier}}
413a3af2bbSChuanqi Xu }
42