public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libstdc++/109536] New: Failure to compile constexpr std::vector with -D_GLIBCXX_DEBUG
@ 2023-04-17 12:43 terra at gnome dot org
  2023-04-17 20:41 ` [Bug libstdc++/109536] " jakub at gcc dot gnu.org
                   ` (8 more replies)
  0 siblings, 9 replies; 10+ messages in thread
From: terra at gnome dot org @ 2023-04-17 12:43 UTC (permalink / raw)
  To: gcc-bugs

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 ()
      | ^~~

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2024-01-18 16:51 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-04-17 12:43 [Bug libstdc++/109536] New: Failure to compile constexpr std::vector with -D_GLIBCXX_DEBUG terra at gnome dot org
2023-04-17 20:41 ` [Bug libstdc++/109536] " jakub at gcc dot gnu.org
2023-04-17 20:41 ` jakub at gcc dot gnu.org
2023-04-18 11:21 ` redi at gcc dot gnu.org
2023-12-05 23:15 ` redi at gcc dot gnu.org
2023-12-06 14:30 ` redi at gcc dot gnu.org
2023-12-14 16:34 ` cvs-commit at gcc dot gnu.org
2023-12-14 16:35 ` redi at gcc dot gnu.org
2024-01-18 15:36 ` cvs-commit at gcc dot gnu.org
2024-01-18 16:51 ` redi at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).