public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/102341] New: [modules] alias-declaration and typedef-declaration conflict in module interface unit
@ 2021-09-15  9:46 redi at gcc dot gnu.org
  2021-09-15  9:52 ` [Bug c++/102341] " redi at gcc dot gnu.org
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: redi at gcc dot gnu.org @ 2021-09-15  9:46 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102341

            Bug ID: 102341
           Summary: [modules] alias-declaration and typedef-declaration
                    conflict in module interface unit
           Product: gcc
           Version: 12.0
            Status: UNCONFIRMED
          Keywords: rejects-valid
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: redi at gcc dot gnu.org
  Target Milestone: ---

export module test;

namespace Test
{
  typedef long Long;
}

namespace Test
{
  export using Long = long;
}

I think this is valid, and it is accepted by 'clang++ -std=c++20' and by
'cl.exe /std:c++20 /experimental:module /interface' but is rejected by G++:


$ g++ -std=c++20 -fmodules-ts -fmodule-only mod.cc
mod.cc:10:27: error: conflicting exporting declaration 'using Long = long int'
   10 |   export using Long = long;
      |                           ^
mod.cc:5:16: note: previous declaration 'typedef long int Test::Long' here
    5 |   typedef long Long;
      |                ^~~~
mod.cc:1:8: warning: not writing module 'test' due to errors
    1 | export module test;
      |        ^~~~~~

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug c++/102341] [modules] alias-declaration and typedef-declaration conflict in module interface unit
  2021-09-15  9:46 [Bug c++/102341] New: [modules] alias-declaration and typedef-declaration conflict in module interface unit redi at gcc dot gnu.org
@ 2021-09-15  9:52 ` redi at gcc dot gnu.org
  2021-09-15 10:34 ` redi at gcc dot gnu.org
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: redi at gcc dot gnu.org @ 2021-09-15  9:52 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102341

--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> ---
In fact it fails even with identical declarations:

export module test;
namespace Test
{
  typedef long Long;
  export typedef long Long;
}


mod.cc:5:23: error: conflicting exporting declaration 'Test::Long'
    5 |   export typedef long Long;
      |                       ^~~~
mod.cc:4:16: note: previous declaration 'typedef long int Test::Long' here
    4 |   typedef long Long;
      |                ^~~~
mod.cc:1:8: warning: not writing module 'test' due to errors
    1 | export module test;
      |        ^~~~~~

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug c++/102341] [modules] alias-declaration and typedef-declaration conflict in module interface unit
  2021-09-15  9:46 [Bug c++/102341] New: [modules] alias-declaration and typedef-declaration conflict in module interface unit redi at gcc dot gnu.org
  2021-09-15  9:52 ` [Bug c++/102341] " redi at gcc dot gnu.org
@ 2021-09-15 10:34 ` redi at gcc dot gnu.org
  2021-09-15 11:28 ` [Bug c++/102341] [modules] "error: conflicting exporting declaration" for anything previously declared redi at gcc dot gnu.org
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: redi at gcc dot gnu.org @ 2021-09-15 10:34 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102341

--- Comment #2 from Jonathan Wakely <redi at gcc dot gnu.org> ---
It seems to happen for almost any redeclaration if the initial definition
wasn't exported:

export module test;
namespace Test
{
  template<typename T> constexpr void f(T) { }
  export template<typename T> constexpr void f(T);
}


mod.cc:5:49: error: conflicting exporting declaration 'template<class T>
constexpr void Test::f(T)'
    5 |   export template<typename T> constexpr void f(T);
      |                                                 ^
mod.cc:4:39: note: previous declaration 'template<class T> constexpr void
Test::f(T)' here
    4 |   template<typename T> constexpr void f(T) { }
      |                                       ^
mod.cc:1:8: warning: not writing module 'test' due to errors
    1 | export module test;
      |        ^~~~~~



This seems to make it impractical to create a module interface unit for any
library that is currently defined in header files, such as libstdc++.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug c++/102341] [modules] "error: conflicting exporting declaration" for anything previously declared
  2021-09-15  9:46 [Bug c++/102341] New: [modules] alias-declaration and typedef-declaration conflict in module interface unit redi at gcc dot gnu.org
  2021-09-15  9:52 ` [Bug c++/102341] " redi at gcc dot gnu.org
  2021-09-15 10:34 ` redi at gcc dot gnu.org
@ 2021-09-15 11:28 ` redi at gcc dot gnu.org
  2021-09-15 11:37 ` pilarlatiesa at gmail dot com
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: redi at gcc dot gnu.org @ 2021-09-15 11:28 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102341

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
     Ever confirmed|0                           |1
   Last reconfirmed|                            |2021-09-15

--- Comment #3 from Jonathan Wakely <redi at gcc dot gnu.org> ---
(In reply to Jonathan Wakely from comment #2)
> This seems to make it impractical to create a module interface unit for any
> library that is currently defined in header files, such as libstdc++.

I can work around this by adding 'export' into the headers themselves (as a
macro that expands to nothing unless included from the module interface unit).

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug c++/102341] [modules] "error: conflicting exporting declaration" for anything previously declared
  2021-09-15  9:46 [Bug c++/102341] New: [modules] alias-declaration and typedef-declaration conflict in module interface unit redi at gcc dot gnu.org
                   ` (2 preceding siblings ...)
  2021-09-15 11:28 ` [Bug c++/102341] [modules] "error: conflicting exporting declaration" for anything previously declared redi at gcc dot gnu.org
@ 2021-09-15 11:37 ` pilarlatiesa at gmail dot com
  2021-09-15 11:50 ` redi at gcc dot gnu.org
  2023-11-25  1:45 ` cvs-commit at gcc dot gnu.org
  5 siblings, 0 replies; 7+ messages in thread
From: pilarlatiesa at gmail dot com @ 2021-09-15 11:37 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102341

Pilar Latiesa <pilarlatiesa at gmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |pilarlatiesa at gmail dot com

--- Comment #4 from Pilar Latiesa <pilarlatiesa at gmail dot com> ---
In PR98885#C1 Nathan said that "an exported entity must be so-declared on its
first declaration".


Would it be possible to forward-declare every exported entity and then
`#include`ing all the headers?

I mean something along the lines:

$ cat borrar.h

namespace Test
{
  template<typename T>
  class valarray {};
}

$ cat borrar.cpp

export module Test;

namespace Test
{
  export
  template<typename T>
  class valarray;
}

#include "borrar.h"

$ cat main.cpp

import Test;

int main()
{
  Test::valarray<double> v;
  return 0;
}

$ g++-11 -Wall -Wextra -fmodules-ts borrar.cpp main.cpp
main.cpp: In function ‘int main()’:
main.cpp:6:26: warning: unused variable ‘v’ [-Wunused-variable]
    6 |   Test::valarray<double> v;
      |                          ^

However, I don't think that this approach can be used to split the library into
several modules.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug c++/102341] [modules] "error: conflicting exporting declaration" for anything previously declared
  2021-09-15  9:46 [Bug c++/102341] New: [modules] alias-declaration and typedef-declaration conflict in module interface unit redi at gcc dot gnu.org
                   ` (3 preceding siblings ...)
  2021-09-15 11:37 ` pilarlatiesa at gmail dot com
@ 2021-09-15 11:50 ` redi at gcc dot gnu.org
  2023-11-25  1:45 ` cvs-commit at gcc dot gnu.org
  5 siblings, 0 replies; 7+ messages in thread
From: redi at gcc dot gnu.org @ 2021-09-15 11:50 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102341

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|---                         |DUPLICATE

--- Comment #5 from Jonathan Wakely <redi at gcc dot gnu.org> ---
A dup then.

*** This bug has been marked as a duplicate of bug 98885 ***

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug c++/102341] [modules] "error: conflicting exporting declaration" for anything previously declared
  2021-09-15  9:46 [Bug c++/102341] New: [modules] alias-declaration and typedef-declaration conflict in module interface unit redi at gcc dot gnu.org
                   ` (4 preceding siblings ...)
  2021-09-15 11:50 ` redi at gcc dot gnu.org
@ 2023-11-25  1:45 ` cvs-commit at gcc dot gnu.org
  5 siblings, 0 replies; 7+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2023-11-25  1:45 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102341

--- Comment #6 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Nathaniel Shead <nshead@gcc.gnu.org>:

https://gcc.gnu.org/g:9dd8be6fc2debc4fbd0950386d4e98878af27a45

commit r14-5838-g9dd8be6fc2debc4fbd0950386d4e98878af27a45
Author: Nathaniel Shead <nathanieloshead@gmail.com>
Date:   Mon Nov 13 16:48:36 2023 +1100

    c++: Allow exporting a typedef redeclaration [PR102341]

    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>

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2023-11-25  1:45 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-15  9:46 [Bug c++/102341] New: [modules] alias-declaration and typedef-declaration conflict in module interface unit redi at gcc dot gnu.org
2021-09-15  9:52 ` [Bug c++/102341] " redi at gcc dot gnu.org
2021-09-15 10:34 ` redi at gcc dot gnu.org
2021-09-15 11:28 ` [Bug c++/102341] [modules] "error: conflicting exporting declaration" for anything previously declared redi at gcc dot gnu.org
2021-09-15 11:37 ` pilarlatiesa at gmail dot com
2021-09-15 11:50 ` redi at gcc dot gnu.org
2023-11-25  1:45 ` cvs-commit at gcc dot gnu.org

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).