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

            Bug ID: 127081
           Summary: Within std::format, constexpr expansion of
                    std::basic_format_string errors with: strong_ordering
                    is not a member of 'std'
           Product: gcc
           Version: 16.2.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: sebj_coder3 at pm dot me
  Target Milestone: ---

I'm getting an error when compiling a C++ module which makes use of
std::format. I think the code should compile, because clang-20 and up do so
without error.

The error output is:
-------------------------------
/opt/gcc16/bin/g++  -I/home/seb/src/mathplot -I/home/seb/src/mathplot/maths
-I/home/seb/src/mathplot/json/include -isystem /usr/include/freetype2
-static-libstdc++ -g -Wall -Wextra -Wpedantic -pedantic-errors -Werror
-Wfatal-errors -Wno-psabi -Wno-unknown-pragmas -O3
-fconstexpr-ops-limit=5000000000
-DMPLOT_FONTS_DIR="\"/home/seb/src/mathplot/fonts\""  -freport-bug -std=gnu++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 file included from /home/seb/src/mathplot/maths/sm/mat.cppm:27,
of module sm.mat, imported at
/home/seb/src/mathplot/mplot/VisualCommon.cppm:20,
of module mplot.visualcommon, imported at
/home/seb/src/mathplot/mplot/VisualResources.cppm:30,
of module mplot.visualresources, imported at
/home/seb/src/mathplot/mplot/Visual.cppm:35,
of module mplot.visual, imported at
/home/seb/src/mathplot/examples/helloworld.cpp:1:
/opt/gcc16/include/c++/16.2.1/format: In instantiation of 'constexpr void
std::__format::_Scanner<_CharT>::_M_scan() [with _CharT = char]':
/opt/gcc16/include/c++/16.2.1/format:5392:19:   required from 'static
std::string sm::[email protected]<F, Nr, Nc>::str_arr(const sm::[email protected]<F, (Nr *
Nc)>&, uint32_t) [with F = float; unsigned int Nr = 4; unsigned int Nc = 4;
std::string = std::__cxx11::basic_string<char>; uint32_t = unsigned int]'
 5392 |         __scanner._M_scan();
      |         ~~~~~~~~~~~~~~~~~^~
/home/seb/src/mathplot/maths/sm/mat.cppm:200:28:   required from 'std::string
sm::[email protected]<F, Nr, Nc>::str_arr(uint32_t) const [with F = float; unsigned
int Nr = 4; unsigned int Nc = 4; std::string =
std::__cxx11::basic_string<char>; uint32_t = unsigned int]'
  200 |             return str_arr (this->arr, prec);
      |                    ~~~~~~~~^~~~~~~~~~~~~~~~~
/home/seb/src/mathplot/mplot/VisualOwnable.cppm:1906:86:   required from 'bool
mplot::[email protected]<glver>::key_callback(int32_t, int32_t,
int32_t, int32_t) [with bool owned = true; int glver = 262145; int32_t = int]'
 1906 |                 std::cout << "  Sceneview matrix array:\n" <<
this->sceneview.str_arr() << std::endl;
      |                                                              
~~~~~~~~~~~~~~~~~~~~~~~^~
/home/seb/src/mathplot/mplot/Visual.cppm:305:77:   required from 'bool
mplot::[email protected]<glver>::key_callback(int32_t, int32_t, int32_t,
int32_t) [with int glver = 262145; int32_t = int]'
  305 |             return mplot::VisualOwnable<glver>::template
key_callback<true> (_key, scancode, action, mods);
      |                   
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/seb/src/mathplot/mplot/Visual.cppm:254:23:   required from 'static void
mplot::[email protected]<glver>::key_callback_dispatch(GLFWwindow*, int32_t,
int32_t, int32_t, int32_t) [with int glver = 262145; GLFWwindow = GLFWwindow;
int32_t = int]'
  254 |             if (self->key_callback (key, scancode, action, mods)) {
      |                 ~~~~~~^~~~~~~~~~~~
/home/seb/src/mathplot/mplot/Visual.cppm:230:32:   required from 'void
mplot::[email protected]<glver>::init_window() [with int glver = 262145]'
  230 |             glfwSetKeyCallback (this->window, key_callback_dispatch);
      |             ~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/seb/src/mathplot/mplot/Visual.cppm:99:19:   required from 'void
mplot::[email protected]<glver>::init_resources() [with int glver = 262145]'
   99 |             this->init_window();
      |             ~~~~~~^~~~~~~~~~~
/home/seb/src/mathplot/mplot/Visual.cppm:73:19:   required from
'mplot::[email protected]<glver>::Visual(int32_t, int32_t, const
std::string&, bool) [with int glver = 262145; int32_t = int; std::string =
std::__cxx11::basic_string<char>]'
   73 |             this->init_resources();
      |             ~~~~~~^~~~~~~~~~~~~~
/home/seb/src/mathplot/examples/helloworld.cpp:6:69:   required from here
    6 |     mplot::Visual<mplot::gl::version_4_1> v(600, 400, "Hello World!");
      |                                                                     ^
/home/seb/src/mathplot/maths/sm/mat.cppm:187:38:   in 'constexpr' expansion of
'std::basic_format_string<char, const float&, const unsigned int&>("{:.{}}, ")'
  187 |                    s += std::format ("{:.{}}, ", _arr[i], prec);
      |                                      ^~~~~~~~~~
/opt/gcc16/include/c++/16.2.1/format:5016:32: error: 'strong_ordering' is not a
member of 'std'
 5016 |             auto __cmp = __lbr <=> __rbr;
      |                          ~~~~~~^~~~~~~~~
compilation terminated due to -Wfatal-errors.
-------------------------------


mat.cppm comes from https://github.com/sebsjames/maths. The build that
generates the error is https://github.com/sebsjames/mathplot.

sm::mat is exported from a module sm.mat. The offending call to mat::str_arr()
is found in mplot::VisualOwnable, which is exported from module
mplot.visualownable, and is the base class for mplot::Visual, exported from
mplot.visual.

I have not yet been able to make a reduced example (first attempt compiled
find; I always find this difficult!).

To reproduce the error:

Install some prerequisites for this OpenGL program. On Ubuntu/Debian it's
these:

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

PLUS g++ compiled from master or release-16 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 bugs/std_format_no_strong_ordering_in_std branch:

 cd mathplot
 git checkout bugs/std_format_no_strong_ordering_in_std
 git submodule update

Build the 'helloworld' target using cmake:

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

Reply via email to