[Bug c++/100707] [modules] ICE on nested namespace

2021-05-20 Thread amorvincitomnia.iw at gmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100707

--- Comment #1 from wang ivor  ---
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{
}

[Bug c++/100707] New: [modules] ICE on nested namespace

2021-05-20 Thread amorvincitomnia.iw at gmail dot com via 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  for instructions.

[Bug c++/100616] [modules] ICE when a variable of class taking a non-type template argument is defined both inside and outside the module

2021-05-16 Thread amorvincitomnia.iw at gmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100616

--- Comment #2 from wang ivor  ---
One workaround I found is to always use templates to refer to C inside modules
and only ever instantiate them in the outermost translation units. 

Or, if you only instantiate C with template arguments of primitive types (e.g.
int, char, pointer types of primitive types, etc.) this bug doesn't happen.

[Bug c++/100617] [modules] Exported namespace not visible from outside when the module imports another module that declares the same namespace

2021-05-16 Thread amorvincitomnia.iw at gmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100617

--- Comment #1 from wang ivor  ---
A workaround is to create a module that exports only the namespace A and
'export import' it in the module 'test1'.

[Bug c++/100616] [modules] ICE when a variable of class taking a non-type template argument is defined both inside and outside the module

2021-05-15 Thread amorvincitomnia.iw at gmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100616

--- Comment #1 from wang ivor  ---
Seems like the same bug happens whenever you use a class template with a
non-type template argument in two modules with dependency. This seems to be a
pretty serious bug that renders non-type template argument basically unusable
inside modules.

[Bug c++/100617] New: [modules] Exported namespace not visible from outside when the module imports another module that declares the same namespace

2021-05-15 Thread amorvincitomnia.iw at gmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100617

Bug ID: 100617
   Summary: [modules] Exported namespace not visible from outside
when the module imports another module that declares
the same namespace
   Product: gcc
   Version: 11.1.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/1Tgk83eCk7VYm3a3


Minimum code to reproduce the error:

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

//test1.cc
export module test1;
import test2;
export namespace A{
int a = 3;
}

//prog.cc
import test1;

void g(){
A::a;
}



Compile it with:

$ g++ "-std=c++20" "-fmodules-ts" "test2.cc" "test1.cc" "prog.cc"



Results in error:

prog.cc: In function 'void g()':
prog.cc:5:5: error: 'A' has not been declared
5 | A::a;
  | ^



Reproduces in both g++ 11.1.0 and g++ 12.0.0 20210510.

[Bug c++/100616] New: [modules] ICE when a class template taking a non-type template argument is used both inside and outside the defining module

2021-05-15 Thread amorvincitomnia.iw at gmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100616

Bug ID: 100616
   Summary: [modules] ICE when a class template taking a non-type
template argument is used both inside and outside the
defining module
   Product: gcc
   Version: 11.1.1
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/QUKvRN5GI1feSldA


Minimal code to reproduce ICE:

// test.cc
export module test;

export
{
struct A{};
template 
struct C {
};

C c1;
}

// prog.cc
import test;
C<1> c2;



Compile this with:

$ g++ "-std=c++20" "-fmodules-ts" "test.cc" "prog.cc"



Generates:

In module test, imported at prog.cc:2:
test.cc: In instantiation of 'struct C@test<1>':
prog.cc:3:6:   required from here
test.cc:8:12: internal compiler error: Segmentation fault
8 | struct C {
  |^
0xcac40f crash_signal
../../source/gcc/toplev.c:327
0x7e6673 comptypes(tree_node*, tree_node*, int)
../../source/gcc/cp/typeck.c:1544
0x7e6673 comptypes(tree_node*, tree_node*, int)
../../source/gcc/cp/typeck.c:1527
0x6a894f complete_vars(tree_node*)
../../source/gcc/cp/decl.c:17761
0x65f97b finish_struct_1(tree_node*)
../../source/gcc/cp/class.c:7505
0x7b1014 instantiate_class_template_1
../../source/gcc/cp/pt.c:12248
0x7b1e42 instantiate_class_template(tree_node*)
../../source/gcc/cp/pt.c:12288
0x7e380b complete_type(tree_node*)
../../source/gcc/cp/typeck.c:143
0x7e380b complete_type(tree_node*)
../../source/gcc/cp/typeck.c:111
0x6a1aeb start_decl_1(tree_node*, bool)
../../source/gcc/cp/decl.c:5677
0x6b283f start_decl(cp_declarator const*, cp_decl_specifier_seq*, int,
tree_node*, tree_node*, tree_node**)
../../source/gcc/cp/decl.c:5643
0x771343 cp_parser_init_declarator
../../source/gcc/cp/parser.c:21759
0x74fac4 cp_parser_simple_declaration
../../source/gcc/cp/parser.c:14464
0x779cb5 cp_parser_declaration
../../source/gcc/cp/parser.c:14161
0x77a98e cp_parser_toplevel_declaration
../../source/gcc/cp/parser.c:14190
0x77a98e cp_parser_translation_unit
../../source/gcc/cp/parser.c:4942
0x77a98e c_parse_file()
../../source/gcc/cp/parser.c:45372
0x84b46d 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  for instructions.


Reproduces in both g++ 11.1.0 and 12.0.0 20210510.