
According to [[dcl.type.elab] p2](http://eel.is/c++draft/dcl.type.elab#2): > If an [elaborated-type-specifier](http://eel.is/c++draft/dcl.type.elab#nt:elaborated-type-specifier) is the sole constituent of a declaration, the declaration is ill-formed unless it is an explicit specialization, an explicit instantiation or it has one of the following forms [...] Consider the following: ```cpp template<typename T> struct A { template<typename U> struct B; }; template<> template<typename U> struct A<int>::B; // #1 ``` The _elaborated-type-specifier_ at `#1` declares an explicit specialization (which is itself a template). We currently (incorrectly) reject this, and this PR fixes that. I moved the point at which _elaborated-type-specifiers_ with _nested-name-specifiers_ are diagnosed from `ParsedFreeStandingDeclSpec` to `ActOnTag` for two reasons: `ActOnTag` isn't called for explicit instantiations and partial/explicit specializations, and because it's where we determine if a member specialization is being declared. With respect to diagnostics, I am currently issuing the diagnostic without marking the declaration as invalid or returning early, which results in more diagnostics that I think is necessary. I would like feedback regarding what the "correct" behavior should be here.
42 lines
2.0 KiB
C++
42 lines
2.0 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> struct X<T>::iterator; // expected-error {{cannot export 'iterator' as it is not at namespace scope}}
|
|
// expected-error@-1 {{forward declaration of struct cannot have a nested name specifier}}
|
|
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}}
|
|
// expected-error@-1 {{forward declaration of struct cannot have a nested name specifier}}
|
|
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> struct X<T>::iterator; // expected-error {{cannot export 'iterator' as it is not at namespace scope}}
|
|
// expected-error@-1 {{forward declaration of struct cannot have a nested name specifier}}
|
|
struct Y::iterator; // expected-error {{cannot export 'iterator' as it is not at namespace scope}}
|
|
// expected-error@-1 {{forward declaration of struct cannot have a nested name specifier}}
|
|
}
|