Index: clang/include/clang/Basic/DiagnosticSemaKinds.td =================================================================== --- clang/include/clang/Basic/DiagnosticSemaKinds.td +++ clang/include/clang/Basic/DiagnosticSemaKinds.td @@ -7781,6 +7781,8 @@ "%select{ or namespace|, namespace, or enumeration}1">; def err_invalid_declarator_scope : Error<"cannot define or redeclare %0 here " "because namespace %1 does not enclose namespace %2">; +def err_invalid_declarator_in_export : Error<"cannot export %0 here " + "because it had be declared in %1.">; def err_invalid_declarator_global_scope : Error< "definition or redeclaration of %0 cannot name the global scope">; def err_invalid_declarator_in_function : Error< Index: clang/lib/Sema/SemaDecl.cpp =================================================================== --- clang/lib/Sema/SemaDecl.cpp +++ clang/lib/Sema/SemaDecl.cpp @@ -5745,6 +5745,9 @@ else if (isa(Cur)) Diag(Loc, diag::err_invalid_declarator_in_block) << Name << SS.getRange(); + else if (isa(Cur)) + Diag(Loc, diag::err_invalid_declarator_in_export) + << Name << cast(DC) << SS.getRange(); else Diag(Loc, diag::err_invalid_declarator_scope) << Name << cast(Cur) << cast(DC) << SS.getRange(); Index: clang/test/CXX/module/module.interface/p6.cpp =================================================================== --- /dev/null +++ clang/test/CXX/module/module.interface/p6.cpp @@ -0,0 +1,12 @@ +// RUN: %clang_cc1 -std=c++20 %s -verify + +export module X; + +export template +struct btree_set { + struct iterator { + T node; + }; +}; + +export template btree_set::iterator; // expected-error {{cannot export 'iterator' here because it had be declared in 'btree_set'}}