Skip to content

[Clang] Fix export declaration diagnostic message #149059

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion clang/include/clang/Basic/DiagnosticSemaKinds.td
Original file line number Diff line number Diff line change
Expand Up @@ -12357,7 +12357,7 @@ def err_export_using_internal : Error<
"using declaration referring to %1 with %select{internal|module|unknown}0 "
"linkage cannot be exported">;
def err_export_not_in_module_interface : Error<
"export declaration can only be used within a module purview">;
"export declaration can only be used within a module interface">;
def err_export_inline_not_defined : Error<
"inline function not defined%select{| before the private module fragment}0">;
def err_export_partition_impl : Error<
Expand Down
4 changes: 2 additions & 2 deletions clang/test/CXX/drs/cwg8xx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
namespace cwg820 { // cwg820: 2.7
export template <class T> struct B {};
// cxx98-17-warning@-1 {{exported templates are unsupported}}
// since-cxx20-error@-2 {{export declaration can only be used within a module purview}}
// since-cxx20-error@-2 {{export declaration can only be used within a module interface}}
export template<typename T> void f() {}
// cxx98-17-warning@-1 {{exported templates are unsupported}}
// since-cxx20-error@-2 {{export declaration can only be used within a module purview}}
// since-cxx20-error@-2 {{export declaration can only be used within a module interface}}
} // namespace cwg820

namespace cwg873 { // cwg873: 3.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

//--- ExportDeclNotInModulePurview.cppm
// expected-error@* {{missing 'export module' declaration in module interface unit}}
export int b; // expected-error {{export declaration can only be used within a module purview}}
export int b; // expected-error {{export declaration can only be used within a module interface}}

//--- A.cppm
// expected-no-diagnostics
Expand All @@ -18,7 +18,7 @@ export int a;

//--- AddExport.cppm
module A; // #module-decl
export int b; // expected-error {{export declaration can only be used within a module purview}}
export int b; // expected-error {{export declaration can only be used within a module interface}}
// expected-note@#module-decl {{add 'export' here}}

//--- AddExport2.cppm
Expand Down
6 changes: 3 additions & 3 deletions clang/test/CXX/module/module.interface/p1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

//--- errors.cpp
module;
export int a; // expected-error {{export declaration can only be used within a module purview}}
export int a; // expected-error {{export declaration can only be used within a module interface}}
export module M;
export int b; // #1
namespace N {
Expand Down Expand Up @@ -37,8 +37,8 @@ namespace N {
//--- impl.cpp
module M; // #M

export int b2; // expected-error {{export declaration can only be used within a module purview}}
export int b2; // expected-error {{export declaration can only be used within a module interface}}
namespace N {
export int c2; // expected-error {{export declaration can only be used within a module purview}}
export int c2; // expected-error {{export declaration can only be used within a module interface}}
}
// expected-note@#M 2+{{add 'export'}}
2 changes: 1 addition & 1 deletion clang/test/Modules/cxx20-10-2-ex1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export int x;
module;

#include "std-10-2-ex1.h"
// [email protected]:* {{export declaration can only be used within a module purview}}
// [email protected]:* {{export declaration can only be used within a module interface}}

export module M1;
export namespace {} // expected-error {{anonymous namespaces cannot be exported}}
Expand Down
2 changes: 1 addition & 1 deletion clang/test/Modules/cxx20-export-import.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@
export module dummy;

//--- test.cpp
export import dummy; // expected-error {{export declaration can only be used within a module purview}}
export import dummy; // expected-error {{export declaration can only be used within a module interface}}
2 changes: 1 addition & 1 deletion clang/test/Modules/cxx20-import-diagnostics-a.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ module;

module AOK1;

export import C; // expected-error {{export declaration can only be used within a module purview}}
export import C; // expected-error {{export declaration can only be used within a module interface}}

int theAnswer () { return 42; }

Expand Down
2 changes: 1 addition & 1 deletion clang/test/Modules/export-in-non-modules.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// RUN: %clang_cc1 -std=c++20 %s -fsyntax-only -verify
export struct Unit { // expected-error {{export declaration can only be used within a module purview}}
export struct Unit { // expected-error {{export declaration can only be used within a module interface}}
bool operator<(const Unit &);
};
Loading