* [PATCH] c++/modules: check mismatching exports for class tags [PR98885]
@ 2023-11-12 12:00 Nathaniel Shead
2023-11-13 6:09 ` [PATCH 2/1] c++/modules: Allow exporting a typedef redeclaration Nathaniel Shead
2023-11-23 16:42 ` [PATCH] c++/modules: check mismatching exports for class tags [PR98885] Nathan Sidwell
0 siblings, 2 replies; 6+ messages in thread
From: Nathaniel Shead @ 2023-11-12 12:00 UTC (permalink / raw)
To: gcc-patches; +Cc: Jason Merrill, Nathan Sidwell
I think the error message is still a little bit unclear but I couldn't
come up with something clearer that was similarly concise and matching
the existing style.
(Also I noticed that the linked PR was assigned to Nathan but there
hadn't been activity for a while, and I've been looking into these kinds
of issues recently anyway so I thought I'd give it a go.)
Bootstrapped and regtested on x86_64-pc-linux-gnu. I don't have write
access.
-- >8 --
Checks for exporting a declaration that was previously declared as not
exported is implemented in 'duplicate_decls', but this doesn't handle
declarations of classes. This patch adds these checks and slightly
adjusts the associated error messages for clarity.
PR c++/98885
gcc/cp/ChangeLog:
* decl.cc (duplicate_decls): Adjust error message.
(xref_tag): Adjust error message. Check exporting decl that is
already declared as non-exporting.
gcc/testsuite/ChangeLog:
* g++.dg/modules/export-1.C: Adjust error messages. Remove
xfails for working case. Add new test case.
Signed-off-by: Nathaniel Shead <nathanieloshead@gmail.com>
---
gcc/cp/decl.cc | 21 ++++++++++++++++++---
gcc/testsuite/g++.dg/modules/export-1.C | 16 +++++++++-------
2 files changed, 27 insertions(+), 10 deletions(-)
diff --git a/gcc/cp/decl.cc b/gcc/cp/decl.cc
index 4a07c7e879b..bde9bd79d58 100644
--- a/gcc/cp/decl.cc
+++ b/gcc/cp/decl.cc
@@ -2236,8 +2236,10 @@ duplicate_decls (tree newdecl, tree olddecl, bool hiding, bool was_hidden)
if (DECL_MODULE_EXPORT_P (STRIP_TEMPLATE (newdecl))
&& !DECL_MODULE_EXPORT_P (not_tmpl))
{
- error ("conflicting exporting declaration %qD", newdecl);
- inform (olddecl_loc, "previous declaration %q#D here", olddecl);
+ auto_diagnostic_group d;
+ error ("conflicting exporting for declaration %qD", newdecl);
+ inform (olddecl_loc,
+ "previously declared here without exporting");
}
}
else if (DECL_MODULE_EXPORT_P (newdecl))
@@ -16249,11 +16251,24 @@ xref_tag (enum tag_types tag_code, tree name,
tree decl = TYPE_NAME (t);
if (!module_may_redeclare (decl))
{
+ auto_diagnostic_group d;
error ("cannot declare %qD in a different module", decl);
- inform (DECL_SOURCE_LOCATION (decl), "declared here");
+ inform (DECL_SOURCE_LOCATION (decl), "previously declared here");
return error_mark_node;
}
+ tree not_tmpl = STRIP_TEMPLATE (decl);
+ if (DECL_LANG_SPECIFIC (not_tmpl)
+ && DECL_MODULE_ATTACH_P (not_tmpl)
+ && !DECL_MODULE_EXPORT_P (not_tmpl)
+ && module_exporting_p ())
+ {
+ auto_diagnostic_group d;
+ error ("conflicting exporting for declaration %qD", decl);
+ inform (DECL_SOURCE_LOCATION (decl),
+ "previously declared here without exporting");
+ }
+
tree maybe_tmpl = decl;
if (CLASS_TYPE_P (t) && CLASSTYPE_IS_TEMPLATE (t))
maybe_tmpl = CLASSTYPE_TI_TEMPLATE (t);
diff --git a/gcc/testsuite/g++.dg/modules/export-1.C b/gcc/testsuite/g++.dg/modules/export-1.C
index 8ca696ebee0..3f93814d270 100644
--- a/gcc/testsuite/g++.dg/modules/export-1.C
+++ b/gcc/testsuite/g++.dg/modules/export-1.C
@@ -4,19 +4,21 @@ export module frob;
// { dg-module-cmi !frob }
int x ();
-export int x (); // { dg-error "conflicting exporting declaration" }
+export int x (); // { dg-error "conflicting exporting for declaration" }
int y;
-export extern int y; // { dg-error "conflicting exporting declaration" }
+export extern int y; // { dg-error "conflicting exporting for declaration" }
typedef int z;
-export typedef int z; // { dg-error "conflicting exporting declaration" }
+export typedef int z; // { dg-error "conflicting exporting for declaration" }
template <typename T> int f (T);
-export template <typename T> int f (T); // { dg-error "conflicting exporting declaration" }
+export template <typename T> int f (T); // { dg-error "conflicting exporting for declaration" }
-// doesn't go via duplicate_decls so we miss this for now
class A;
-export class A; // { dg-error "conflicting exporting declaration" "" { xfail *-*-* } }
+export class A; // { dg-error "conflicting exporting for declaration" }
-// { dg-warning "due to errors" "" { target *-*-* } 0 }
+template <typename T> struct B;
+export template <typename T> struct B {}; // { dg-error "conflicting exporting for declaration" }
+
+// { dg-warning "due to errors" "" { target *-*-* } 0 }
--
2.42.0
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH 2/1] c++/modules: Allow exporting a typedef redeclaration
2023-11-12 12:00 [PATCH] c++/modules: check mismatching exports for class tags [PR98885] Nathaniel Shead
@ 2023-11-13 6:09 ` Nathaniel Shead
2023-11-23 16:45 ` Nathan Sidwell
2023-11-23 16:42 ` [PATCH] c++/modules: check mismatching exports for class tags [PR98885] Nathan Sidwell
1 sibling, 1 reply; 6+ messages in thread
From: Nathaniel Shead @ 2023-11-13 6:09 UTC (permalink / raw)
To: gcc-patches; +Cc: Jason Merrill, Nathan Sidwell
I happened to be browsing the standard a bit later and noticed that we
incorrectly reject the example given below.
Bootstrapped on x86_64-pc-linux-gnu; regtesting ongoing but modules.exp
completed with no errors.
-- >8 --
A typedef doesn't create a new entity, and thus should be allowed to be
exported even if it has been previously declared un-exported. See the
example in [module.interface] p6:
export module M;
struct S { int n; };
typedef S S;
export typedef S S; // OK, does not redeclare an entity
PR c++/102341
gcc/cp/ChangeLog:
* decl.cc (duplicate_decls): Allow exporting a redeclaration of
a typedef.
gcc/testsuite/ChangeLog:
* g++.dg/modules/export-1.C: Adjust test.
Signed-off-by: Nathaniel Shead <nathanieloshead@gmail.com>
---
gcc/cp/decl.cc | 5 ++++-
gcc/testsuite/g++.dg/modules/export-1.C | 6 +++++-
2 files changed, 9 insertions(+), 2 deletions(-)
diff --git a/gcc/cp/decl.cc b/gcc/cp/decl.cc
index bde9bd79d58..5e175d3e835 100644
--- a/gcc/cp/decl.cc
+++ b/gcc/cp/decl.cc
@@ -2231,7 +2231,10 @@ duplicate_decls (tree newdecl, tree olddecl, bool hiding, bool was_hidden)
}
tree not_tmpl = STRIP_TEMPLATE (olddecl);
- if (DECL_LANG_SPECIFIC (not_tmpl) && DECL_MODULE_ATTACH_P (not_tmpl))
+ if (DECL_LANG_SPECIFIC (not_tmpl)
+ && DECL_MODULE_ATTACH_P (not_tmpl)
+ /* Typedefs are not entities and so can be exported later. */
+ && TREE_CODE (olddecl) != TYPE_DECL)
{
if (DECL_MODULE_EXPORT_P (STRIP_TEMPLATE (newdecl))
&& !DECL_MODULE_EXPORT_P (not_tmpl))
diff --git a/gcc/testsuite/g++.dg/modules/export-1.C b/gcc/testsuite/g++.dg/modules/export-1.C
index 3f93814d270..598814370ec 100644
--- a/gcc/testsuite/g++.dg/modules/export-1.C
+++ b/gcc/testsuite/g++.dg/modules/export-1.C
@@ -9,8 +9,12 @@ export int x (); // { dg-error "conflicting exporting for declaration" }
int y;
export extern int y; // { dg-error "conflicting exporting for declaration" }
+// A typedef is not an entity so the following is OK; see [module.interface] example 4
typedef int z;
-export typedef int z; // { dg-error "conflicting exporting for declaration" }
+export typedef int z; // { dg-bogus "conflicting exporting for declaration" }
+
+template <typename T> using w = T;
+export template <typename T> using w = T; // { dg-error "conflicting exporting for declaration" }
template <typename T> int f (T);
export template <typename T> int f (T); // { dg-error "conflicting exporting for declaration" }
--
2.42.0
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] c++/modules: check mismatching exports for class tags [PR98885]
2023-11-12 12:00 [PATCH] c++/modules: check mismatching exports for class tags [PR98885] Nathaniel Shead
2023-11-13 6:09 ` [PATCH 2/1] c++/modules: Allow exporting a typedef redeclaration Nathaniel Shead
@ 2023-11-23 16:42 ` Nathan Sidwell
1 sibling, 0 replies; 6+ messages in thread
From: Nathan Sidwell @ 2023-11-23 16:42 UTC (permalink / raw)
To: Nathaniel Shead, gcc-patches; +Cc: Jason Merrill
On 11/12/23 07:00, Nathaniel Shead wrote:
> I think the error message is still a little bit unclear but I couldn't
> come up with something clearer that was similarly concise and matching
> the existing style.
>
> (Also I noticed that the linked PR was assigned to Nathan but there
> hadn't been activity for a while, and I've been looking into these kinds
> of issues recently anyway so I thought I'd give it a go.)
>
> Bootstrapped and regtested on x86_64-pc-linux-gnu. I don't have write
> access.
ok
>
> -- >8 --
>
> Checks for exporting a declaration that was previously declared as not
> exported is implemented in 'duplicate_decls', but this doesn't handle
> declarations of classes. This patch adds these checks and slightly
> adjusts the associated error messages for clarity.
>
> PR c++/98885
>
> gcc/cp/ChangeLog:
>
> * decl.cc (duplicate_decls): Adjust error message.
> (xref_tag): Adjust error message. Check exporting decl that is
> already declared as non-exporting.
>
> gcc/testsuite/ChangeLog:
>
> * g++.dg/modules/export-1.C: Adjust error messages. Remove
> xfails for working case. Add new test case.
>
> Signed-off-by: Nathaniel Shead <nathanieloshead@gmail.com>
> ---
> gcc/cp/decl.cc | 21 ++++++++++++++++++---
> gcc/testsuite/g++.dg/modules/export-1.C | 16 +++++++++-------
> 2 files changed, 27 insertions(+), 10 deletions(-)
>
> diff --git a/gcc/cp/decl.cc b/gcc/cp/decl.cc
> index 4a07c7e879b..bde9bd79d58 100644
> --- a/gcc/cp/decl.cc
> +++ b/gcc/cp/decl.cc
> @@ -2236,8 +2236,10 @@ duplicate_decls (tree newdecl, tree olddecl, bool hiding, bool was_hidden)
> if (DECL_MODULE_EXPORT_P (STRIP_TEMPLATE (newdecl))
> && !DECL_MODULE_EXPORT_P (not_tmpl))
> {
> - error ("conflicting exporting declaration %qD", newdecl);
> - inform (olddecl_loc, "previous declaration %q#D here", olddecl);
> + auto_diagnostic_group d;
> + error ("conflicting exporting for declaration %qD", newdecl);
> + inform (olddecl_loc,
> + "previously declared here without exporting");
> }
> }
> else if (DECL_MODULE_EXPORT_P (newdecl))
> @@ -16249,11 +16251,24 @@ xref_tag (enum tag_types tag_code, tree name,
> tree decl = TYPE_NAME (t);
> if (!module_may_redeclare (decl))
> {
> + auto_diagnostic_group d;
> error ("cannot declare %qD in a different module", decl);
> - inform (DECL_SOURCE_LOCATION (decl), "declared here");
> + inform (DECL_SOURCE_LOCATION (decl), "previously declared here");
> return error_mark_node;
> }
>
> + tree not_tmpl = STRIP_TEMPLATE (decl);
> + if (DECL_LANG_SPECIFIC (not_tmpl)
> + && DECL_MODULE_ATTACH_P (not_tmpl)
> + && !DECL_MODULE_EXPORT_P (not_tmpl)
> + && module_exporting_p ())
> + {
> + auto_diagnostic_group d;
> + error ("conflicting exporting for declaration %qD", decl);
> + inform (DECL_SOURCE_LOCATION (decl),
> + "previously declared here without exporting");
> + }
> +
> tree maybe_tmpl = decl;
> if (CLASS_TYPE_P (t) && CLASSTYPE_IS_TEMPLATE (t))
> maybe_tmpl = CLASSTYPE_TI_TEMPLATE (t);
> diff --git a/gcc/testsuite/g++.dg/modules/export-1.C b/gcc/testsuite/g++.dg/modules/export-1.C
> index 8ca696ebee0..3f93814d270 100644
> --- a/gcc/testsuite/g++.dg/modules/export-1.C
> +++ b/gcc/testsuite/g++.dg/modules/export-1.C
> @@ -4,19 +4,21 @@ export module frob;
> // { dg-module-cmi !frob }
>
> int x ();
> -export int x (); // { dg-error "conflicting exporting declaration" }
> +export int x (); // { dg-error "conflicting exporting for declaration" }
>
> int y;
> -export extern int y; // { dg-error "conflicting exporting declaration" }
> +export extern int y; // { dg-error "conflicting exporting for declaration" }
>
> typedef int z;
> -export typedef int z; // { dg-error "conflicting exporting declaration" }
> +export typedef int z; // { dg-error "conflicting exporting for declaration" }
>
> template <typename T> int f (T);
> -export template <typename T> int f (T); // { dg-error "conflicting exporting declaration" }
> +export template <typename T> int f (T); // { dg-error "conflicting exporting for declaration" }
>
> -// doesn't go via duplicate_decls so we miss this for now
> class A;
> -export class A; // { dg-error "conflicting exporting declaration" "" { xfail *-*-* } }
> +export class A; // { dg-error "conflicting exporting for declaration" }
>
> -// { dg-warning "due to errors" "" { target *-*-* } 0 }
> +template <typename T> struct B;
> +export template <typename T> struct B {}; // { dg-error "conflicting exporting for declaration" }
> +
> +// { dg-warning "due to errors" "" { target *-*-* } 0 }
--
Nathan Sidwell
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 2/1] c++/modules: Allow exporting a typedef redeclaration
2023-11-13 6:09 ` [PATCH 2/1] c++/modules: Allow exporting a typedef redeclaration Nathaniel Shead
@ 2023-11-23 16:45 ` Nathan Sidwell
2023-11-24 2:10 ` [PATCH] c++: Allow exporting a typedef redeclaration [PR102341] Nathaniel Shead
0 siblings, 1 reply; 6+ messages in thread
From: Nathan Sidwell @ 2023-11-23 16:45 UTC (permalink / raw)
To: Nathaniel Shead, gcc-patches; +Cc: Jason Merrill
On 11/13/23 01:09, Nathaniel Shead wrote:
> I happened to be browsing the standard a bit later and noticed that we
> incorrectly reject the example given below.
>
> Bootstrapped on x86_64-pc-linux-gnu; regtesting ongoing but modules.exp
> completed with no errors.
>
> -- >8 --
>
> A typedef doesn't create a new entity, and thus should be allowed to be
> exported even if it has been previously declared un-exported. See the
> example in [module.interface] p6:
ok. Could you put a reference to [module.interface]/p6 in the comment though?
nathan
>
> export module M;
> struct S { int n; };
> typedef S S;
> export typedef S S; // OK, does not redeclare an entity
>
> PR c++/102341
>
> gcc/cp/ChangeLog:
>
> * decl.cc (duplicate_decls): Allow exporting a redeclaration of
> a typedef.
>
> gcc/testsuite/ChangeLog:
>
> * g++.dg/modules/export-1.C: Adjust test.
>
> Signed-off-by: Nathaniel Shead <nathanieloshead@gmail.com>
> ---
> gcc/cp/decl.cc | 5 ++++-
> gcc/testsuite/g++.dg/modules/export-1.C | 6 +++++-
> 2 files changed, 9 insertions(+), 2 deletions(-)
>
> diff --git a/gcc/cp/decl.cc b/gcc/cp/decl.cc
> index bde9bd79d58..5e175d3e835 100644
> --- a/gcc/cp/decl.cc
> +++ b/gcc/cp/decl.cc
> @@ -2231,7 +2231,10 @@ duplicate_decls (tree newdecl, tree olddecl, bool hiding, bool was_hidden)
> }
>
> tree not_tmpl = STRIP_TEMPLATE (olddecl);
> - if (DECL_LANG_SPECIFIC (not_tmpl) && DECL_MODULE_ATTACH_P (not_tmpl))
> + if (DECL_LANG_SPECIFIC (not_tmpl)
> + && DECL_MODULE_ATTACH_P (not_tmpl)
> + /* Typedefs are not entities and so can be exported later. */
> + && TREE_CODE (olddecl) != TYPE_DECL)
> {
> if (DECL_MODULE_EXPORT_P (STRIP_TEMPLATE (newdecl))
> && !DECL_MODULE_EXPORT_P (not_tmpl))
> diff --git a/gcc/testsuite/g++.dg/modules/export-1.C b/gcc/testsuite/g++.dg/modules/export-1.C
> index 3f93814d270..598814370ec 100644
> --- a/gcc/testsuite/g++.dg/modules/export-1.C
> +++ b/gcc/testsuite/g++.dg/modules/export-1.C
> @@ -9,8 +9,12 @@ export int x (); // { dg-error "conflicting exporting for declaration" }
> int y;
> export extern int y; // { dg-error "conflicting exporting for declaration" }
>
> +// A typedef is not an entity so the following is OK; see [module.interface] example 4
> typedef int z;
> -export typedef int z; // { dg-error "conflicting exporting for declaration" }
> +export typedef int z; // { dg-bogus "conflicting exporting for declaration" }
> +
> +template <typename T> using w = T;
> +export template <typename T> using w = T; // { dg-error "conflicting exporting for declaration" }
>
> template <typename T> int f (T);
> export template <typename T> int f (T); // { dg-error "conflicting exporting for declaration" }
--
Nathan Sidwell
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH] c++: Allow exporting a typedef redeclaration [PR102341]
2023-11-23 16:45 ` Nathan Sidwell
@ 2023-11-24 2:10 ` Nathaniel Shead
2023-11-24 22:05 ` Nathan Sidwell
0 siblings, 1 reply; 6+ messages in thread
From: Nathaniel Shead @ 2023-11-24 2:10 UTC (permalink / raw)
To: Nathan Sidwell; +Cc: gcc-patches, Jason Merrill
On Thu, Nov 23, 2023 at 11:45:31AM -0500, Nathan Sidwell wrote:
> On 11/13/23 01:09, Nathaniel Shead wrote:
> > I happened to be browsing the standard a bit later and noticed that we
> > incorrectly reject the example given below.
> >
> > Bootstrapped on x86_64-pc-linux-gnu; regtesting ongoing but modules.exp
> > completed with no errors.
> >
> > -- >8 --
> >
> > A typedef doesn't create a new entity, and thus should be allowed to be
> > exported even if it has been previously declared un-exported. See the
> > example in [module.interface] p6:
>
> ok. Could you put a reference to [module.interface]/p6 in the comment though?
>
> nathan
>
Thanks. I've also added a new test to ensure that the redeclarations are
actually exported. Ok for trunk?
-- >8 --
A typedef doesn't create a new entity, and thus should be allowed to be
exported even if it has been previously declared un-exported. See the
example in [module.interface] p6:
export module M;
struct S { int n; };
typedef S S;
export typedef S S; // OK, does not redeclare an entity
PR c++/102341
gcc/cp/ChangeLog:
* decl.cc (duplicate_decls): Allow exporting a redeclaration of
a typedef.
gcc/testsuite/ChangeLog:
* g++.dg/modules/export-1.C: Adjust test.
* g++.dg/modules/export-2_a.C: New test.
* g++.dg/modules/export-2_b.C: New test.
Signed-off-by: Nathaniel Shead <nathanieloshead@gmail.com>
---
gcc/cp/decl.cc | 6 +++++-
gcc/testsuite/g++.dg/modules/export-1.C | 6 +++++-
gcc/testsuite/g++.dg/modules/export-2_a.C | 14 ++++++++++++++
gcc/testsuite/g++.dg/modules/export-2_b.C | 7 +++++++
4 files changed, 31 insertions(+), 2 deletions(-)
create mode 100644 gcc/testsuite/g++.dg/modules/export-2_a.C
create mode 100644 gcc/testsuite/g++.dg/modules/export-2_b.C
diff --git a/gcc/cp/decl.cc b/gcc/cp/decl.cc
index 16b04ebe0f8..f8324f92ca7 100644
--- a/gcc/cp/decl.cc
+++ b/gcc/cp/decl.cc
@@ -2231,7 +2231,11 @@ duplicate_decls (tree newdecl, tree olddecl, bool hiding, bool was_hidden)
}
tree not_tmpl = STRIP_TEMPLATE (olddecl);
- if (DECL_LANG_SPECIFIC (not_tmpl) && DECL_MODULE_ATTACH_P (not_tmpl))
+ if (DECL_LANG_SPECIFIC (not_tmpl)
+ && DECL_MODULE_ATTACH_P (not_tmpl)
+ /* Typedefs are not entities and so are OK to be redeclared
+ as exported: see [module.interface] p6. */
+ && TREE_CODE (olddecl) != TYPE_DECL)
{
if (DECL_MODULE_EXPORT_P (STRIP_TEMPLATE (newdecl))
&& !DECL_MODULE_EXPORT_P (not_tmpl))
diff --git a/gcc/testsuite/g++.dg/modules/export-1.C b/gcc/testsuite/g++.dg/modules/export-1.C
index 3f93814d270..598814370ec 100644
--- a/gcc/testsuite/g++.dg/modules/export-1.C
+++ b/gcc/testsuite/g++.dg/modules/export-1.C
@@ -9,8 +9,12 @@ export int x (); // { dg-error "conflicting exporting for declaration" }
int y;
export extern int y; // { dg-error "conflicting exporting for declaration" }
+// A typedef is not an entity so the following is OK; see [module.interface] example 4
typedef int z;
-export typedef int z; // { dg-error "conflicting exporting for declaration" }
+export typedef int z; // { dg-bogus "conflicting exporting for declaration" }
+
+template <typename T> using w = T;
+export template <typename T> using w = T; // { dg-error "conflicting exporting for declaration" }
template <typename T> int f (T);
export template <typename T> int f (T); // { dg-error "conflicting exporting for declaration" }
diff --git a/gcc/testsuite/g++.dg/modules/export-2_a.C b/gcc/testsuite/g++.dg/modules/export-2_a.C
new file mode 100644
index 00000000000..9a201bf37c0
--- /dev/null
+++ b/gcc/testsuite/g++.dg/modules/export-2_a.C
@@ -0,0 +1,14 @@
+// { dg-additional-options "-fmodules-ts" }
+// { dg-module-cmi aliases }
+
+export module aliases;
+
+typedef int x;
+export typedef int x;
+
+using y = double;
+export using y = double;
+
+struct S {};
+using T = S;
+export using T = S;
diff --git a/gcc/testsuite/g++.dg/modules/export-2_b.C b/gcc/testsuite/g++.dg/modules/export-2_b.C
new file mode 100644
index 00000000000..456aa8d9ec8
--- /dev/null
+++ b/gcc/testsuite/g++.dg/modules/export-2_b.C
@@ -0,0 +1,7 @@
+// { dg-additional-options "-fmodules-ts" }
+
+import aliases;
+
+x a = 123;
+y b = 12.45;
+T c = T{};
--
2.42.0
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] c++: Allow exporting a typedef redeclaration [PR102341]
2023-11-24 2:10 ` [PATCH] c++: Allow exporting a typedef redeclaration [PR102341] Nathaniel Shead
@ 2023-11-24 22:05 ` Nathan Sidwell
0 siblings, 0 replies; 6+ messages in thread
From: Nathan Sidwell @ 2023-11-24 22:05 UTC (permalink / raw)
To: Nathaniel Shead; +Cc: gcc-patches, Jason Merrill
On 11/23/23 21:10, Nathaniel Shead wrote:
> On Thu, Nov 23, 2023 at 11:45:31AM -0500, Nathan Sidwell wrote:
>> On 11/13/23 01:09, Nathaniel Shead wrote:
>>> I happened to be browsing the standard a bit later and noticed that we
>>> incorrectly reject the example given below.
>>>
>>> Bootstrapped on x86_64-pc-linux-gnu; regtesting ongoing but modules.exp
>>> completed with no errors.
>>>
>>> -- >8 --
>>>
>>> A typedef doesn't create a new entity, and thus should be allowed to be
>>> exported even if it has been previously declared un-exported. See the
>>> example in [module.interface] p6:
>>
>> ok. Could you put a reference to [module.interface]/p6 in the comment though?
>>
>> nathan
>>
>
> Thanks. I've also added a new test to ensure that the redeclarations are
> actually exported. Ok for trunk?
ok
>
> -- >8 --
>
> A typedef doesn't create a new entity, and thus should be allowed to be
> exported even if it has been previously declared un-exported. See the
> example in [module.interface] p6:
>
> export module M;
> struct S { int n; };
> typedef S S;
> export typedef S S; // OK, does not redeclare an entity
>
> PR c++/102341
>
> gcc/cp/ChangeLog:
>
> * decl.cc (duplicate_decls): Allow exporting a redeclaration of
> a typedef.
>
> gcc/testsuite/ChangeLog:
>
> * g++.dg/modules/export-1.C: Adjust test.
> * g++.dg/modules/export-2_a.C: New test.
> * g++.dg/modules/export-2_b.C: New test.
>
> Signed-off-by: Nathaniel Shead <nathanieloshead@gmail.com>
> ---
> gcc/cp/decl.cc | 6 +++++-
> gcc/testsuite/g++.dg/modules/export-1.C | 6 +++++-
> gcc/testsuite/g++.dg/modules/export-2_a.C | 14 ++++++++++++++
> gcc/testsuite/g++.dg/modules/export-2_b.C | 7 +++++++
> 4 files changed, 31 insertions(+), 2 deletions(-)
> create mode 100644 gcc/testsuite/g++.dg/modules/export-2_a.C
> create mode 100644 gcc/testsuite/g++.dg/modules/export-2_b.C
>
> diff --git a/gcc/cp/decl.cc b/gcc/cp/decl.cc
> index 16b04ebe0f8..f8324f92ca7 100644
> --- a/gcc/cp/decl.cc
> +++ b/gcc/cp/decl.cc
> @@ -2231,7 +2231,11 @@ duplicate_decls (tree newdecl, tree olddecl, bool hiding, bool was_hidden)
> }
>
> tree not_tmpl = STRIP_TEMPLATE (olddecl);
> - if (DECL_LANG_SPECIFIC (not_tmpl) && DECL_MODULE_ATTACH_P (not_tmpl))
> + if (DECL_LANG_SPECIFIC (not_tmpl)
> + && DECL_MODULE_ATTACH_P (not_tmpl)
> + /* Typedefs are not entities and so are OK to be redeclared
> + as exported: see [module.interface] p6. */
> + && TREE_CODE (olddecl) != TYPE_DECL)
> {
> if (DECL_MODULE_EXPORT_P (STRIP_TEMPLATE (newdecl))
> && !DECL_MODULE_EXPORT_P (not_tmpl))
> diff --git a/gcc/testsuite/g++.dg/modules/export-1.C b/gcc/testsuite/g++.dg/modules/export-1.C
> index 3f93814d270..598814370ec 100644
> --- a/gcc/testsuite/g++.dg/modules/export-1.C
> +++ b/gcc/testsuite/g++.dg/modules/export-1.C
> @@ -9,8 +9,12 @@ export int x (); // { dg-error "conflicting exporting for declaration" }
> int y;
> export extern int y; // { dg-error "conflicting exporting for declaration" }
>
> +// A typedef is not an entity so the following is OK; see [module.interface] example 4
> typedef int z;
> -export typedef int z; // { dg-error "conflicting exporting for declaration" }
> +export typedef int z; // { dg-bogus "conflicting exporting for declaration" }
> +
> +template <typename T> using w = T;
> +export template <typename T> using w = T; // { dg-error "conflicting exporting for declaration" }
>
> template <typename T> int f (T);
> export template <typename T> int f (T); // { dg-error "conflicting exporting for declaration" }
> diff --git a/gcc/testsuite/g++.dg/modules/export-2_a.C b/gcc/testsuite/g++.dg/modules/export-2_a.C
> new file mode 100644
> index 00000000000..9a201bf37c0
> --- /dev/null
> +++ b/gcc/testsuite/g++.dg/modules/export-2_a.C
> @@ -0,0 +1,14 @@
> +// { dg-additional-options "-fmodules-ts" }
> +// { dg-module-cmi aliases }
> +
> +export module aliases;
> +
> +typedef int x;
> +export typedef int x;
> +
> +using y = double;
> +export using y = double;
> +
> +struct S {};
> +using T = S;
> +export using T = S;
> diff --git a/gcc/testsuite/g++.dg/modules/export-2_b.C b/gcc/testsuite/g++.dg/modules/export-2_b.C
> new file mode 100644
> index 00000000000..456aa8d9ec8
> --- /dev/null
> +++ b/gcc/testsuite/g++.dg/modules/export-2_b.C
> @@ -0,0 +1,7 @@
> +// { dg-additional-options "-fmodules-ts" }
> +
> +import aliases;
> +
> +x a = 123;
> +y b = 12.45;
> +T c = T{};
--
Nathan Sidwell
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2023-11-24 22:05 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-11-12 12:00 [PATCH] c++/modules: check mismatching exports for class tags [PR98885] Nathaniel Shead
2023-11-13 6:09 ` [PATCH 2/1] c++/modules: Allow exporting a typedef redeclaration Nathaniel Shead
2023-11-23 16:45 ` Nathan Sidwell
2023-11-24 2:10 ` [PATCH] c++: Allow exporting a typedef redeclaration [PR102341] Nathaniel Shead
2023-11-24 22:05 ` Nathan Sidwell
2023-11-23 16:42 ` [PATCH] c++/modules: check mismatching exports for class tags [PR98885] Nathan Sidwell
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).