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
* [Bug libstdc++/109536] Failure to compile constexpr std::vector with -D_GLIBCXX_DEBUG
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 ` jakub at gcc dot gnu.org
2023-04-17 20:41 ` jakub at gcc dot gnu.org
` (7 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: jakub at gcc dot gnu.org @ 2023-04-17 20:41 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109536
Jakub Jelinek <jakub at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |jakub at gcc dot gnu.org
--- Comment #1 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
12-5187-g1ae8edf5f73ca5c3 acknowledged that:
libstdc++: Implement constexpr std::vector for C++20
This implements P1004R2 ("Making std::vector constexpr") for C++20.
For now, debug mode vectors are not supported in constant expressions.
To make that work we might need to disable all attaching/detaching of
safe iterators. That can be fixed later.
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug libstdc++/109536] Failure to compile constexpr std::vector with -D_GLIBCXX_DEBUG
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
` (6 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: jakub at gcc dot gnu.org @ 2023-04-17 20:41 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109536
--- Comment #2 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
r12-5187-g1ae8edf5f73ca5c3 even.
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug libstdc++/109536] Failure to compile constexpr std::vector with -D_GLIBCXX_DEBUG
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
` (5 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: redi at gcc dot gnu.org @ 2023-04-18 11:21 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109536
--- Comment #3 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Right - using std::vector in constant expressions isn't supported by debug
mode. Somebody needs to work on that.
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug libstdc++/109536] Failure to compile constexpr std::vector with -D_GLIBCXX_DEBUG
2023-04-17 12:43 [Bug libstdc++/109536] New: Failure to compile constexpr std::vector with -D_GLIBCXX_DEBUG terra at gnome dot org
` (2 preceding siblings ...)
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
` (4 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: redi at gcc dot gnu.org @ 2023-12-05 23:15 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109536
Jonathan Wakely <redi at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |NEW
Ever confirmed|0 |1
Last reconfirmed| |2023-12-05
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug libstdc++/109536] Failure to compile constexpr std::vector with -D_GLIBCXX_DEBUG
2023-04-17 12:43 [Bug libstdc++/109536] New: Failure to compile constexpr std::vector with -D_GLIBCXX_DEBUG terra at gnome dot org
` (3 preceding siblings ...)
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
` (3 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: redi at gcc dot gnu.org @ 2023-12-06 14:30 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109536
Jonathan Wakely <redi at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Keywords| |patch
--- Comment #4 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Patch posted:
https://gcc.gnu.org/pipermail/gcc-patches/2023-December/639592.html
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug libstdc++/109536] Failure to compile constexpr std::vector with -D_GLIBCXX_DEBUG
2023-04-17 12:43 [Bug libstdc++/109536] New: Failure to compile constexpr std::vector with -D_GLIBCXX_DEBUG terra at gnome dot org
` (4 preceding siblings ...)
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
` (2 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2023-12-14 16:34 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109536
--- Comment #5 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Jonathan Wakely <redi@gcc.gnu.org>:
https://gcc.gnu.org/g:7d00a59229ee17af009a3c6c6208b0611740ed49
commit r14-6553-g7d00a59229ee17af009a3c6c6208b0611740ed49
Author: Jonathan Wakely <jwakely@redhat.com>
Date: Wed Dec 6 13:39:52 2023 +0000
libstdc++: Make __gnu_debug::vector usable in constant expressions
[PR109536]
This makes constexpr std::vector (mostly) work in Debug Mode. All safe
iterator instrumentation and checking is disabled during constant
evaluation, because it requires mutex locks and calls to non-inline
functions defined in libstdc++.so. It should be OK to disable the safety
checks, because most UB should be detected during constant evaluation
anyway.
We could try to enable the full checking in constexpr, but it would mean
wrapping all the non-inline functions like _M_attach with an inline
_M_constexpr_attach that does the iterator housekeeping inline without
mutex locks when called for constant evaluation, and calls the
non-inline function at runtime. That could be done in future if we find
that we've lost safety or useful checking by disabling the safe
iterators.
There are a few test failures in C++20 mode, which I'm unable to
explain. The _Safe_iterator::operator++() member gives errors for using
non-constexpr functions during constant evaluation, even though those
functions are guarded by std::is_constant_evaluated() checks. The same
code works fine for C++23 and up.
libstdc++-v3/ChangeLog:
PR libstdc++/109536
* include/bits/c++config (__glibcxx_constexpr_assert): Remove
macro.
* include/bits/stl_algobase.h (__niter_base, __copy_move_a)
(__copy_move_backward_a, __fill_a, __fill_n_a, __equal_aux)
(__lexicographical_compare_aux): Add constexpr to overloads for
debug mode iterators.
* include/debug/helper_functions.h (__unsafe): Add constexpr.
* include/debug/macros.h (_GLIBCXX_DEBUG_VERIFY_COND_AT): Remove
macro, folding it into ...
(_GLIBCXX_DEBUG_VERIFY_AT_F): ... here. Do not use
__glibcxx_constexpr_assert.
* include/debug/safe_base.h (_Safe_iterator_base): Add constexpr
to some member functions. Omit attaching, detaching and checking
operations during constant evaluation.
* include/debug/safe_container.h (_Safe_container): Likewise.
* include/debug/safe_iterator.h (_Safe_iterator): Likewise.
* include/debug/safe_iterator.tcc (__niter_base, __copy_move_a)
(__copy_move_backward_a, __fill_a, __fill_n_a, __equal_aux)
(__lexicographical_compare_aux): Add constexpr.
* include/debug/vector (_Safe_vector, vector): Add constexpr.
Omit safe iterator operations during constant evaluation.
* testsuite/23_containers/vector/bool/capacity/constexpr.cc:
Remove dg-xfail-if for debug mode.
* testsuite/23_containers/vector/bool/cmp_c++20.cc: Likewise.
* testsuite/23_containers/vector/bool/cons/constexpr.cc:
Likewise.
* testsuite/23_containers/vector/bool/element_access/1.cc:
Likewise.
* testsuite/23_containers/vector/bool/element_access/constexpr.cc:
Likewise.
*
testsuite/23_containers/vector/bool/modifiers/assign/constexpr.cc:
Likewise.
* testsuite/23_containers/vector/bool/modifiers/constexpr.cc:
Likewise.
* testsuite/23_containers/vector/bool/modifiers/swap/constexpr.cc:
Likewise.
* testsuite/23_containers/vector/capacity/constexpr.cc:
Likewise.
* testsuite/23_containers/vector/cmp_c++20.cc: Likewise.
* testsuite/23_containers/vector/cons/constexpr.cc: Likewise.
* testsuite/23_containers/vector/data_access/constexpr.cc:
Likewise.
* testsuite/23_containers/vector/element_access/constexpr.cc:
Likewise.
* testsuite/23_containers/vector/modifiers/assign/constexpr.cc:
Likewise.
* testsuite/23_containers/vector/modifiers/constexpr.cc:
Likewise.
* testsuite/23_containers/vector/modifiers/swap/constexpr.cc:
Likewise.
* testsuite/23_containers/vector/cons/destructible_debug_neg.cc:
Adjust dg-error line number.
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug libstdc++/109536] Failure to compile constexpr std::vector with -D_GLIBCXX_DEBUG
2023-04-17 12:43 [Bug libstdc++/109536] New: Failure to compile constexpr std::vector with -D_GLIBCXX_DEBUG terra at gnome dot org
` (5 preceding siblings ...)
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
8 siblings, 0 replies; 10+ messages in thread
From: redi at gcc dot gnu.org @ 2023-12-14 16:35 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109536
Jonathan Wakely <redi at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|NEW |RESOLVED
Resolution|--- |FIXED
Target Milestone|--- |14.0
--- Comment #6 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Fixed for GCC 14
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug libstdc++/109536] Failure to compile constexpr std::vector with -D_GLIBCXX_DEBUG
2023-04-17 12:43 [Bug libstdc++/109536] New: Failure to compile constexpr std::vector with -D_GLIBCXX_DEBUG terra at gnome dot org
` (6 preceding siblings ...)
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
8 siblings, 0 replies; 10+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2024-01-18 15:36 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109536
--- Comment #7 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Patrick Palka <ppalka@gcc.gnu.org>:
https://gcc.gnu.org/g:3d3145e9e1461e92bef02d55d36990261dd0444d
commit r14-8252-g3d3145e9e1461e92bef02d55d36990261dd0444d
Author: Patrick Palka <ppalka@redhat.com>
Date: Thu Jan 18 10:36:07 2024 -0500
libstdc++/debug: Fix constexpr _Safe_iterator in C++20 mode [PR109536]
Some _Safe_iterator member functions define a variable of non-literal
type __gnu_cxx::__scoped_lock, which automatically disqualifies them from
being constexpr in C++20 mode even if that code path is never constant
evaluated. This restriction was lifted by P2242R3 for C++23, but we
need to work around it in C++20 mode. To that end this patch defines
a pair of macros that encapsulate the lambda-based workaround mentioned
in that paper and uses it to make these functions valid C++20 constexpr
functions. The augmented std::vector test element_access/constexpr.cc
now successfully compiles in C++20 mode with -D_GLIBCXX_DEBUG (and it
should test all member functions modified by this patch).
PR libstdc++/109536
libstdc++-v3/ChangeLog:
* include/debug/safe_base.h (_Safe_sequence_base::_M_swap):
Remove _GLIBCXX20_CONSTEXPR from non-inline member function.
* include/debug/safe_iterator.h
(_GLIBCXX20_CONSTEXPR_NON_LITERAL_SCOPE_BEGIN): Define.
(_GLIBCXX20_CONSTEXPR_NON_LITERAL_SCOPE_END): Define.
(_Safe_iterator::operator=): Use them around the code path that
defines a variable of type __gnu_cxx::__scoped_lock.
(_Safe_iterator::operator++): Likewise.
(_Safe_iterator::operator--): Likewise.
(_Safe_iterator::operator+=): Likewise.
(_Safe_iterator::operator-=): Likewise.
* testsuite/23_containers/vector/element_access/constexpr.cc
(test_iterators): Test more iterator operations.
* testsuite/23_containers/vector/bool/element_access/constexpr.cc
(test_iterators): Likewise.
* testsuite/std/ranges/adaptors/all.cc (test08) [_GLIBCXX_DEBUG]:
Remove.
Reviewed-by: Jonathan Wakely <jwakely@redhat.com>
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug libstdc++/109536] Failure to compile constexpr std::vector with -D_GLIBCXX_DEBUG
2023-04-17 12:43 [Bug libstdc++/109536] New: Failure to compile constexpr std::vector with -D_GLIBCXX_DEBUG terra at gnome dot org
` (7 preceding siblings ...)
2024-01-18 15:36 ` cvs-commit at gcc dot gnu.org
@ 2024-01-18 16:51 ` redi at gcc dot gnu.org
8 siblings, 0 replies; 10+ messages in thread
From: redi at gcc dot gnu.org @ 2024-01-18 16:51 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109536
--- Comment #8 from Jonathan Wakely <redi at gcc dot gnu.org> ---
(In reply to GCC Commits from comment #5)
> There are a few test failures in C++20 mode, which I'm unable to
> explain. The _Safe_iterator::operator++() member gives errors for using
> non-constexpr functions during constant evaluation, even though those
> functions are guarded by std::is_constant_evaluated() checks. The same
> code works fine for C++23 and up.
This part is fixed by Patrick's commit.
^ 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).