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

            Bug ID: 124431
           Summary: See incorrect 'error: accessing uninitialised array
                    element' in C++20 module
           Product: gcc
           Version: 16.0
               URL: https://github.com/sebsjames/mathplot/tree/dev/modules
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: sebj_coder3 at pm dot me
                CC: sebj_coder3 at pm dot me
  Target Milestone: ---

When building a C++ module, I have a compiler error from g++ (built from
master; gcc16-prerelease) that I don't think is correct. clang++-main (version
23 prerelease) is able to compile the module. g++ versions 13 and 14 compile a
header-only version of the same (or at least, very similar) code.

I am afraid I don't have a minimal example for this problem, but here are steps
to reproduce:

Install some prerequisites. On Ubuntu/Debian it's these:

 sudo apt install build-essential git wget \
                  librapidxml-dev ninja-build \
                  freeglut3-dev libglu1-mesa-dev libxmu-dev libxi-dev \
                  libglfw3-dev libfreetype-dev libarmadillo-dev libhdf5-dev

PLUS g++ compiled from master and cmake at least version 3.28.5.

clone mathplot recursively (it has two submodules):

 git clone --recurse-submodules [email protected]:sebsjames/mathplot

switch to the dev/modules branch

 cd mathplot
 git co dev/modules
 git submodule update

Build using cmake:

 mkdir bgcc
 cd bgcc
 CC=/path/to/gcc CXX=/path/to/g++ cmake .. -GNinja
 ninja helloworld

You should see this error output:

[11:37:39 bgcc] ninja helloworld
[1/2] Building CXX object examples/CMakeFiles/helloworld.dir/helloworld.cpp.o
FAILED: examples/CMakeFiles/helloworld.dir/helloworld.cpp.o 
/opt/gcc-master/bin/g++  -I/home/seb/src/mathplot -I/usr/include/hdf5/serial
-I/home/seb/src/mathplot/maths -I/home/seb/src/mathplot/json/include
-I/home/seb/src/mathplot/include/rapidxml-1.13 -isystem /usr/include/freetype2
-g -Wall -Wextra -Wpedantic -pedantic-errors -Werror -Wfatal-errors -Wno-psabi
-O3 -fconstexpr-ops-limit=5000000000 -DMPLOT_HAVE_STD_FORMAT -fopenmp
-DMPLOT_FONTS_DIR="\"/home/seb/src/mathplot/fonts\""  -std=c++20 -MD -MT
examples/CMakeFiles/helloworld.dir/helloworld.cpp.o -MF
examples/CMakeFiles/helloworld.dir/helloworld.cpp.o.d -fmodules-ts
-fmodule-mapper=examples/CMakeFiles/helloworld.dir/helloworld.cpp.o.modmap -MD
-fdeps-format=p1689r5 -x c++ -o
examples/CMakeFiles/helloworld.dir/helloworld.cpp.o -c
/home/seb/src/mathplot/examples/helloworld.cpp
In module sm.mat, imported at /home/seb/src/mathplot/mplot/VisualCommon.h:20,
of module mplot.visualcommon, imported at
/home/seb/src/mathplot/mplot/VisualResources.h:35,
of module mplot.visualresources, imported at
/home/seb/src/mathplot/mplot/Visual.h:34,
of module mplot.visual, imported at
/home/seb/src/mathplot/examples/helloworld.cpp:1:
/home/seb/src/mathplot/maths/sm/mat: In instantiation of ‘void
mplot::[email protected]<glver>::computeSceneview_for_follower()
[with int glver = 262145]’:
/home/seb/src/mathplot/mplot/VisualOwnable.h:1245:23:   required from ‘void
mplot::[email protected]<glver>::computeSceneview() [with int
glver = 262145]’
 1245 |                 this->computeSceneview_for_follower();
      |                 ~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/seb/src/mathplot/mplot/VisualOwnable.h:427:19:   required from ‘void
mplot::[email protected]<glver>::render() [with int glver =
262145]’
  427 |             this->computeSceneview();
      |             ~~~~~~^~~~~~~~~~~~~~~~
/home/seb/src/mathplot/mplot/Visual.h:179:29:   required from ‘void
mplot::[email protected]<glver>::keepOpen() [with int glver = 262145]’
  179 |                 this->render();
      |                 ~~~~~~~~~~~~^~
/home/seb/src/mathplot/examples/helloworld.cpp:8:15:   required from here
    8 |     v.keepOpen();
      |     ~~~~~~~~~~^~
/home/seb/src/mathplot/mplot/VisualOwnable.h:1232:64:   in ‘constexpr’
expansion of
‘mplot::[email protected]<262145>::rotate_about_y()’
 1232 |             constexpr sm::mat<float, 4> rotn_y = rotate_about_y();
      |                                                  ~~~~~~~~~~~~~~^~
/home/seb/src/mathplot/mplot/VisualOwnable.h:1175:22:   in ‘constexpr’
expansion of ‘r.sm::[email protected]<float, 4>::rotate<>(sm::[email protected]<float,
3>{std::array<float, 3>{std::__array_traits<float, 3>::_Type{0.0f, 1.0e+0f}}},
sm::mathconst<float>::pi)’
 1175 |             r.rotate (sm::vec<>::uy(), sm::mathconst<float>::pi);
      |             ~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/seb/src/mathplot/maths/sm/mat:924:29:   in ‘constexpr’ expansion of
‘((sm::[email protected]<float, 4>*)this)->sm::[email protected]<float, 
4>::rotate<float>(q)’
  924 |             this->rotate<T> (q);
      |             ~~~~~~~~~~~~~~~~^~~
/home/seb/src/mathplot/maths/sm/mat:881:77:   in ‘constexpr’ expansion of
‘((sm::[email protected]<float, 4>*)this)->sm::[email protected]<float, 
4>::operator*=<float,
4, 4>(sm::[email protected]<float, 4>::pure_rotation<float>((* & q)))’
  881 |         constexpr void rotate (const sm::quaternion<T>& q) noexcept {
*this *= this->pure_rotation (q); }
      |                                                                      
~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
/home/seb/src/mathplot/maths/sm/mat:1240:64: error: accessing uninitialised
array element
 1240 |                 m[0] = this->arr[0] * m2.arr[0] + this->arr[4] *
m2.arr[1] + this->arr[8] * m2.arr[2] + this->arr[12] * m2.arr[3];
      |                                                  
~~~~~~~~~~~~~^~~~~~~~~
compilation terminated due to -Wfatal-errors.
ninja: build stopped: subcommand failed.

Expected behaviour: The program to compile.

Hope this helps C++ module development.

Reply via email to