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

            Bug ID: 109536
           Summary: Failure to compile constexpr std::vector with
                    -D_GLIBCXX_DEBUG
           Product: gcc
           Version: 12.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libstdc++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: terra at gnome dot org
  Target Milestone: ---

Created attachment 54875
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=54875&action=edit
Preprocessed source code

The following program fails to compile with -std=gnu++20 -D_GLIBCXX_DEBUG
due to the debug version of std::vector::~vector not being constexpr.

It compiles just fine without -D_GLIBCXX_DEBUG.  FWIW, clang 15 sees no problem
(without -D...) other than "farm" being unused.

-------------------------------------------------------------

#include <vector>

constexpr int
foo ()
{
  std::vector<int> v { 1, 2, 3 };
  return v.size();
}

constexpr int farm = foo ();

-------------------------------------------------------------

# /usr/local/products/gcc/12.1.0/bin/g++ -D_GLIBCXX_DEBUG  -std=gnu++20 -Wall
-c www.C
www.C: In function ‘constexpr int foo()’:
www.C:7:20: error: variable ‘v’ of non-literal type ‘std::__debug::vector<int>’
in ‘constexpr’ function only available with ‘-std=c++2b’ or ‘-std=gnu++2b’
    7 |   std::vector<int> v { 1, 2, 3 };
      |                    ^
In file included from
/usr/local/products/gcc/12.1.0/include/c++/12.1.0/vector:74,
                 from www.C:1:
/usr/local/products/gcc/12.1.0/include/c++/12.1.0/debug/vector:117:11: note:
‘std::__debug::vector<int>’ is not literal because:
  117 |     class vector
      |           ^~~~~~
/usr/local/products/gcc/12.1.0/include/c++/12.1.0/debug/vector:117:11: note:  
‘std::__debug::vector<int>’ does not have ‘constexpr’ destructor
www.C: At global scope:
www.C:11:26: error: ‘constexpr int foo()’ called in a constant expression
   11 | constexpr int farm = foo ();
      |                      ~~~~^~
www.C:5:1: note: ‘constexpr int foo()’ declared here
    5 | foo ()
      | ^~~

Reply via email to