mirrored from git://gcc.gnu.org/git/gcc.git
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
c++: Implement P2615 'Meaningful Exports' [PR107688]
This clarifies which kinds of declarations may and may not be exported in various contexts. The patch additionally fixes up some small issues that were clarified by the paper. Most of the changes are with regards to export-declarations, which are applied for all standards modes that we support '-fmodules-ts' for. However there are also a couple of changes made to linkage specifiers ('extern "C"'); I've applied these as since C++20, to line up with when modules were actually introduced. PR c++/107688 gcc/cp/ChangeLog: * name-lookup.cc (push_namespace): Error when exporting namespace with internal linkage. * parser.h (struct cp_parser): Add new flag 'in_unbraced_export_declaration_p'. * parser.cc (cp_debug_parser): Print the new flag. (cp_parser_new): Initialise the new flag. (cp_parser_module_export): Set the new flag. (cp_parser_class_specifier): Clear and restore the new flag. (cp_parser_import_declaration): Imports can now appear directly in a linkage specification. (cp_parser_declaration): Categorise declarations as "name" or "special"; error on the later in contexts where the former is required. (cp_parser_class_head): Error when exporting a partial specialisation. gcc/testsuite/ChangeLog: * g++.dg/modules/contracts-1_a.C: Avoid now-illegal syntax. * g++.dg/modules/contracts-2_a.C: Likewise. * g++.dg/modules/contracts-3_a.C: Likewise. * g++.dg/modules/contracts-4_a.C: Likewise. * g++.dg/modules/lang-1_c.C: Clarify now-legal syntax. * g++.dg/modules/pr101582-1.C: Remove now-legal XFAILS. * g++.dg/template/crash71.C: Update error messages. * g++.dg/cpp2a/linkage-spec1.C: New test. * g++.dg/modules/export-3.C: New test. * g++.dg/modules/export-4_a.C: New test. * g++.dg/modules/export-4_b.C: New test. Signed-off-by: Nathaniel Shead <nathanieloshead@gmail.com>
- Loading branch information
Showing
14 changed files
with
197 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// PR c++/107688 | ||
// P2615R1: Meaningful exports: Newly invalid declarations | ||
// { dg-do compile { target c++11 } } | ||
|
||
extern "C++" template <typename T> struct A {}; | ||
|
||
extern "C++" template <typename T> struct A<T*> {}; | ||
|
||
extern "C++" template <> struct A<int*> {}; | ||
// { dg-error "explicit specializations are not permitted here" "" { target c++20 } .-1 } | ||
|
||
extern "C++" template struct A<int>; | ||
// { dg-error "explicit instantiations are not permitted here" "" { target c++20 } .-1 } | ||
|
||
|
||
// These should all still be valid, though | ||
extern "C++" { | ||
template <typename T> struct B {}; | ||
template <typename T> struct B<T*> {}; | ||
template <> struct B<int*> {}; | ||
template struct B<int>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// P2615R1 invalid declarations | ||
// PR c++/107688 | ||
// { dg-additional-options "-fmodules-ts" } | ||
// { dg-module-cmi !bad } | ||
|
||
export module bad; | ||
|
||
extern "C++" export void foo(); // { dg-error "export-declarations are not permitted here" "" { target c++20 } } | ||
|
||
export template <typename T> struct S {}; | ||
|
||
export template <typename T> struct S<T*> {}; // { dg-error "partial specialization in unbraced export-declaration" } | ||
|
||
export template <> struct S<int*> {}; // { dg-error "explicit specializations are not permitted here" } | ||
|
||
export template struct S<int>; // { dg-error "explicit instantiations are not permitted here" } | ||
|
||
template <> export struct S<double>; // { dg-error "expected unqualified-id" } | ||
|
||
export export int x; // { dg-error ".export. may only occur once" } | ||
|
||
export { export int y; } // { dg-error ".export. may only occur once" } | ||
|
||
namespace { | ||
export namespace ns {} // { dg-error "internal linkage" } | ||
} | ||
|
||
export namespace {} // { dg-error "internal linkage" } | ||
|
||
// { dg-prune-output "not writing module" } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// P2615R1 valid declarations | ||
// PR c++/107688 | ||
// { dg-additional-options "-fmodules-ts" } | ||
// { dg-module-cmi M } | ||
|
||
export module M; | ||
|
||
export {} | ||
export { static_assert(true); } | ||
|
||
export namespace Empty {} | ||
export using namespace Empty; | ||
|
||
export { | ||
template <typename T> struct S {}; | ||
template <typename T> struct S<T*> { using a = int; }; | ||
template <> struct S<int*> { using b = int; }; | ||
template struct S<int>; | ||
} | ||
|
||
extern "C++" { | ||
export void foo(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// PR c++/107688 | ||
// { dg-additional-options "-fmodules-ts" } | ||
|
||
import M; | ||
|
||
using namespace Empty; | ||
|
||
int main() { | ||
S<int> x; | ||
S<int*>::b y; | ||
S<int**>::a z; | ||
foo(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.