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

            Bug ID: 119938
           Summary: [15/16 Regression][modules] Class type NTTPs are not
                    considered constant when imported
           Product: gcc
           Version: 15.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: nshead at gcc dot gnu.org
            Blocks: 103524
  Target Milestone: ---

There are a large number of issues caused by CNTTPs not properly being
considered constant when imported.  Some examples:

===

  // eg1.h
  struct A { int x; };
  template <A a> struct B { static_assert(a.x == 5); };
  using C = B<A{5}>;

  // eg1.cpp
  import "eg1.h";
  C c;

$ g++ -std=c++20 -fmodules -S eg1.h eg1.cpp
eg1.cpp:2:3: error: aggregate ‘C c’ has incomplete type and cannot be defined
    2 | C c;
      |   ^

===

  // eg2.h
  struct A { int x; };
  template <A a> void foo() { static_assert(a.x == 5); };
  inline void bar() { foo<A{5}>(); }

  // eg2.cpp
  import "eg2.h";
  int main() { bar(); }

$ g++ -std=c++20 -fmodules -S eg2.h eg2.cpp
eg2.cpp:2:21: internal compiler error: Segmentation fault
    2 | int main() { bar(); }
      |                     ^
0x3ce0f35 internal_error(char const*, ...)
        ../../gcc/gcc/diagnostic-global-context.cc:517
0x1d35e92 crash_signal
        ../../gcc/gcc/toplev.cc:322
0x7f0490a2732f ???
        ./signal/../sysdeps/unix/sysv/linux/x86_64/libc_sigaction.c:0
0xec9815 tree_check(tree_node const*, char const*, int, char const*, tree_code)
        ../../gcc/gcc/tree.h:3979
0x158fde8 symbol_table::decl_assembler_name_hash(tree_node const*)
        ../../gcc/gcc/symtab.cc:84
0x1592d30 symtab_node::get_for_asmname(tree_node const*)
        ../../gcc/gcc/symtab.cc:1067
0x1592fe1 symtab_node::verify_base()
        ../../gcc/gcc/symtab.cc:1158
0x15ac085 cgraph_node::verify_node()
        ../../gcc/gcc/cgraph.cc:3499
0x159394b symtab_node::verify()
        ../../gcc/gcc/symtab.cc:1362
0x1593d2d symtab_node::verify_symtab_nodes()
        ../../gcc/gcc/symtab.cc:1482
0x15bdd0e symtab_node::checking_verify_symtab_nodes()
        ../../gcc/gcc/cgraph.h:702
0x15bd1e7 symbol_table::compile()
        ../../gcc/gcc/cgraphunit.cc:2332
0x15bd899 symbol_table::finalize_compilation_unit()
        ../../gcc/gcc/cgraphunit.cc:2607
Please submit a full bug report, with preprocessed source (by using
-freport-bug).
Please include the complete backtrace with any bug report.
See <https://gcc.gnu.org/bugs/> for instructions.

===

  // eg3.h
  struct A { int x; };
  template <A a> struct B { static constexpr int result = a.x; };
  template <int=0> constexpr int foo() { return B<A{5}>::result; };

  // eg3.cpp
  import "eg3.h";
  static_assert(foo() == 5);

$ g++ -std=c++20 -fmodules -S eg3.h eg3.cpp
eg3.cpp:2:21: error: non-constant condition for static assertion
    2 | static_assert(foo() == 5);
      |               ~~~~~~^~~~
In module eg3.h, imported at eg3.cpp:1:
eg3.cpp:2:18:   in ‘constexpr’ expansion of ‘foo<>()’
eg3.h:3:56: error: the value of ‘B<A{5}>::result’ is not usable in a constant
expression
    3 | template <int=0> constexpr int foo() { return B<A{5}>::result; };
      |                                               ~~~~~~~~~^~~~~~
eg3.h:2:48: note: ‘B<A{5}>::result’ used in its own initialiser
    2 | template <A a> struct B { static constexpr int result = a; };
                                                       ^~~~~~

==

... and so forth.  This worked correctly in GCC14.  I have a patch that fixes
all these cases.


Referenced Bugs:

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103524
[Bug 103524] [meta-bug] modules issue

Reply via email to