Chuanqi Xu 3a3af2bbc9 [C++20] [Module] fix bug 47716 and implement [module.interface]/p6
This fixes bug 47716.

According to [module.interface]p2, it is meaningless to export an entity
which is not in namespace scope.
The reason why the compiler crashes is that the compiler missed
ExportDecl when the compiler traverse the subclass of DeclContext. So
here is the crash.

Also, the patch implements [module.interface]p6 in
Sema::CheckRedeclaration* functions.

Reviewed By: aaron.ballman, urnathan

Differential Revision: https://reviews.llvm.org/D112903
2022-01-24 10:25:25 +08:00

38 lines
1.4 KiB
C++

// The intention of this file to check we could only export declarations in namesapce scope.
//
// RUN: %clang_cc1 -std=c++20 %s -verify
export module X;
export template <typename T>
struct X {
struct iterator {
T node;
};
void foo() {}
template <typename U>
U bar();
};
export template <typename T> X<T>::iterator; // expected-error {{cannot export 'iterator' as it is not at namespace scope}}
export template <typename T> void X<T>::foo(); // expected-error {{cannot export 'foo' as it is not at namespace scope}}
export template <typename T> template <typename U> U X<T>::bar(); // expected-error {{cannot export 'bar' as it is not at namespace scope}}
export struct Y {
struct iterator {
int node;
};
void foo() {}
template <typename U>
U bar();
};
export struct Y::iterator; // expected-error {{cannot export 'iterator' as it is not at namespace scope}}
export void Y::foo(); // expected-error {{cannot export 'foo' as it is not at namespace scope}}
export template <typename U> U Y::bar(); // expected-error {{cannot export 'bar' as it is not at namespace scope}}
export {
template <typename T> X<T>::iterator; // expected-error {{cannot export 'iterator' as it is not at namespace scope}}
struct Y::iterator; // expected-error {{cannot export 'iterator' as it is not at namespace scope}}
}