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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
     Ever confirmed|0                           |1
                 CC|                            |nshead at gcc dot gnu.org
            Summary|Possibly incorrect 'error:  |[16 Regression] Possibly
                   |accessing uninitialised     |incorrect 'error: accessing
                   |array element' in C++20     |uninitialised array
                   |module                      |element' in C++20 module
   Last reconfirmed|                            |2026-03-10
             Status|UNCONFIRMED                 |NEW
           Keywords|                            |needs-bisection,
                   |                            |rejects-valid

--- Comment #2 from Nathaniel Shead <nshead at gcc dot gnu.org> ---
Confirmed.  Bit of a strange case; here's as reduced as I can get it for now:


// a.cpp
export module A;
export template <int N> struct mat {
  int data[1] = { 123 };
  constexpr const int& operator[](int x) const { return data[x]; };
};

// b.cpp
export module B;
export import A;
struct VisualTextModel {
  mat<4> viewmatrix;
};

// c.cpp
export module C;
export import A;
mat<4> from_triangle_frame;

// d.cpp
export module D;
import C;
import B;
export constexpr mat<4> rotate_about_y() {
  mat<4> r;
  r[0] * 1;
  return r;
}

// e.cpp
import D;
constexpr auto rotn_y = rotate_about_y();

$ g++ -fmodules -S [abcde].cpp
In module D, imported at e.cpp:1:
e.cpp:2:39:   in ‘constexpr’ expansion of ‘rotate_about_y@D()’
    2 | constexpr auto rotn_y = rotate_about_y();
      |                         ~~~~~~~~~~~~~~^~
d.cpp:6:8: error: accessing uninitialized member ‘mat@A<4>::data’
    6 |   r[0] * 1;
      |        ^~~


Swapping the order of importing C and B in module D fixes the issue.  First
quick check looks the NSDMI is getting dropped somewhere.

GCC15 at least can correctly compile the reduced version, so I'll mark as a
regression.

Reply via email to