public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/100707] New: [modules] ICE on nested namespace
@ 2021-05-20 16:24 amorvincitomnia.iw at gmail dot com
  2021-05-20 16:33 ` [Bug c++/100707] " amorvincitomnia.iw at gmail dot com
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: amorvincitomnia.iw at gmail dot com @ 2021-05-20 16:24 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 100707
           Summary: [modules] ICE on nested namespace
           Product: gcc
           Version: 12.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: amorvincitomnia.iw at gmail dot com
  Target Milestone: ---

See it live: https://wandbox.org/permlink/HOMZ2A8ClOzIKXO1

Minimum code to reproduce ICE:

// m3.cc
export module m3;
export namespace A{
}

// m2.cc
export module m2;
import m3;
export namespace A::B{
}

// m1.cc
export module m1;
import m2;
export namespace A::B{
}


Compile it with: 
$ g++ "-std=gnu++20" "-fmodules-ts" "m3.cc" "m2.cc" "m1.cc"

Produces the following ICE:

m1.cc:3:21: internal compiler error: in resume_scope, at cp/name-lookup.c:4417
    3 | export namespace A::B{
      |                     ^
0x5f4ed6 resume_scope
        ../../source/gcc/cp/name-lookup.c:4417
0x7328fb push_namespace(tree_node*, bool)
        ../../source/gcc/cp/name-lookup.c:8882
0x779b37 cp_parser_namespace_definition
        ../../source/gcc/cp/parser.c:20475
0x77a458 cp_parser_declaration
        ../../source/gcc/cp/parser.c:14141
0x77a153 cp_parser_module_export
        ../../source/gcc/cp/parser.c:13951
0x77a153 cp_parser_declaration
        ../../source/gcc/cp/parser.c:14104
0x77ac4e cp_parser_toplevel_declaration
        ../../source/gcc/cp/parser.c:14190
0x77ac4e cp_parser_translation_unit
        ../../source/gcc/cp/parser.c:4942
0x77ac4e c_parse_file()
        ../../source/gcc/cp/parser.c:45393
0x84b7dd c_common_parse_file()
        ../../source/gcc/c-family/c-opts.c:1218
Please submit a full bug report,
with preprocessed source if appropriate.
Please include the complete backtrace with any bug report.
See <https://gcc.gnu.org/bugs/> for instructions.

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

* [Bug c++/100707] [modules] ICE on nested namespace
  2021-05-20 16:24 [Bug c++/100707] New: [modules] ICE on nested namespace amorvincitomnia.iw at gmail dot com
@ 2021-05-20 16:33 ` amorvincitomnia.iw at gmail dot com
  2024-01-25  3:20 ` cvs-commit at gcc dot gnu.org
  2024-02-11 14:09 ` nshead at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: amorvincitomnia.iw at gmail dot com @ 2021-05-20 16:33 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from wang ivor <amorvincitomnia.iw at gmail dot com> ---
A quick workaround: https://wandbox.org/permlink/n8E5xJuJhq1CUA0e

Create a module that only contains the namespace declaration, and 'export
import' it whenever you declare a new namespace.

// namespace_decl.cc

export module namespace_decl;

export namespace A::B{
}

// m2.cc

export module m2;

export import namespace_decl;

import m3;
export namespace A::B{
}

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

* [Bug c++/100707] [modules] ICE on nested namespace
  2021-05-20 16:24 [Bug c++/100707] New: [modules] ICE on nested namespace amorvincitomnia.iw at gmail dot com
  2021-05-20 16:33 ` [Bug c++/100707] " amorvincitomnia.iw at gmail dot com
@ 2024-01-25  3:20 ` cvs-commit at gcc dot gnu.org
  2024-02-11 14:09 ` nshead at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2024-01-25  3:20 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from GCC 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:b433a6f5a0617dcbb28f2462b31198f86aadecaa

commit r14-8407-gb433a6f5a0617dcbb28f2462b31198f86aadecaa
Author: Nathaniel Shead <nathanieloshead@gmail.com>
Date:   Sun Jan 21 00:45:37 2024 +1100

    c++: Fix importing nested namespace declarations [PR100707]

    Currently, importing a namespace declarations marks it as imported, and
    so marks it as originating from the module that it was imported from.
    This is usually harmless, but causes problems with nested namespaces.

    In the linked PR, what happens is that the namespace 'A' imported from
    the module ends up not being considered when creating the 'A' namespace
    within its own TU, and thus it has its 'cp_binding_level' recreated.
    However, by this point 'A::B' has already been imported, and so the
    'level_chain' member no longer correctly points at 'A's binding level,
    so the sanity check for this in 'resume_scope' ICEs.

    Since as far as I can tell there's no reason for imported namespaces to
    be attached to any specific module (namespace declarations with external
    linkage are always attached to the global module by [module.unit] p7.2),
    this patch just removes the 'imported' flag, which stops code from
    caring about its originating module.

    This patch also makes some minor adjustments to existing tests to cater
    for the new dumped name.

            PR c++/100707

    gcc/cp/ChangeLog:

            * name-lookup.cc (add_imported_namespace): Don't mark namespaces
            as imported.

    gcc/testsuite/ChangeLog:

            * g++.dg/modules/indirect-1_b.C: Adjust to handle namespaces not
            being attached to the module they were imported from.
            * g++.dg/modules/indirect-1_c.C: Likewise.
            * g++.dg/modules/indirect-2_b.C: Likewise.
            * g++.dg/modules/indirect-2_c.C: Likewise.
            * g++.dg/modules/indirect-3_b.C: Likewise.
            * g++.dg/modules/indirect-3_c.C: Likewise.
            * g++.dg/modules/indirect-4_b.C: Likewise.
            * g++.dg/modules/indirect-4_c.C: Likewise.
            * g++.dg/modules/namespace-5_a.C: New test.
            * g++.dg/modules/namespace-5_b.C: New test.
            * g++.dg/modules/namespace-5_c.C: New test.

    Signed-off-by: Nathaniel Shead <nathanieloshead@gmail.com>

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

* [Bug c++/100707] [modules] ICE on nested namespace
  2021-05-20 16:24 [Bug c++/100707] New: [modules] ICE on nested namespace amorvincitomnia.iw at gmail dot com
  2021-05-20 16:33 ` [Bug c++/100707] " amorvincitomnia.iw at gmail dot com
  2024-01-25  3:20 ` cvs-commit at gcc dot gnu.org
@ 2024-02-11 14:09 ` nshead at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: nshead at gcc dot gnu.org @ 2024-02-11 14:09 UTC (permalink / raw)
  To: gcc-bugs

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

Nathaniel Shead <nshead at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |FIXED
             Status|UNCONFIRMED                 |RESOLVED
                 CC|                            |nshead at gcc dot gnu.org
           Assignee|unassigned at gcc dot gnu.org      |nshead at gcc dot gnu.org
   Target Milestone|---                         |14.0

--- Comment #3 from Nathaniel Shead <nshead at gcc dot gnu.org> ---
Fixed for GCC 14.

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

end of thread, other threads:[~2024-02-11 14:09 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-20 16:24 [Bug c++/100707] New: [modules] ICE on nested namespace amorvincitomnia.iw at gmail dot com
2021-05-20 16:33 ` [Bug c++/100707] " amorvincitomnia.iw at gmail dot com
2024-01-25  3:20 ` cvs-commit at gcc dot gnu.org
2024-02-11 14:09 ` nshead 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).