public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/106212] New: Code becomes non-constexpr with _GLIBCXX_DEBUG
@ 2022-07-06 8:17 fiesh at zefix dot tv
2022-07-06 8:19 ` [Bug c++/106212] " fiesh at zefix dot tv
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: fiesh at zefix dot tv @ 2022-07-06 8:17 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106212
Bug ID: 106212
Summary: Code becomes non-constexpr with _GLIBCXX_DEBUG
Product: gcc
Version: 13.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: fiesh at zefix dot tv
Target Milestone: ---
Consider the following C++20 code:
#include <array>
struct P {
constexpr P(int i) : e{i} {}
auto operator<=>(P const &) const = default;
std::array<int, 1> e;
};
constexpr auto operator-(P lhs, P) { return lhs; }
constexpr P p{1}, q{0};
static_assert(p - q != 0);
It behaves as follows:
* g++ compiles it successfully
* g++ with -D_GLIBCXX_DEBUG does not compile it
* clang++ compiles it successfully
* clang++ -D_GLIBCXX_DEBUG compiles it successfully
See also https://godbolt.org/z/ve19v1re9
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug c++/106212] Code becomes non-constexpr with _GLIBCXX_DEBUG
2022-07-06 8:17 [Bug c++/106212] New: Code becomes non-constexpr with _GLIBCXX_DEBUG fiesh at zefix dot tv
@ 2022-07-06 8:19 ` fiesh at zefix dot tv
2022-07-06 10:34 ` redi at gcc dot gnu.org
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: fiesh at zefix dot tv @ 2022-07-06 8:19 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106212
--- Comment #1 from fiesh at zefix dot tv ---
Oh and this appears to be a regression introduced in GCC 12.
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug c++/106212] Code becomes non-constexpr with _GLIBCXX_DEBUG
2022-07-06 8:17 [Bug c++/106212] New: Code becomes non-constexpr with _GLIBCXX_DEBUG fiesh at zefix dot tv
2022-07-06 8:19 ` [Bug c++/106212] " fiesh at zefix dot tv
@ 2022-07-06 10:34 ` redi at gcc dot gnu.org
2022-07-06 10:34 ` redi at gcc dot gnu.org
2022-07-06 10:37 ` redi at gcc dot gnu.org
3 siblings, 0 replies; 5+ messages in thread
From: redi at gcc dot gnu.org @ 2022-07-06 10:34 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106212
Jonathan Wakely <redi at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Last reconfirmed| |2022-07-06
Status|UNCONFIRMED |NEW
Ever confirmed|0 |1
--- Comment #2 from Jonathan Wakely <redi at gcc dot gnu.org> ---
(In reply to fiesh from comment #1)
> Oh and this appears to be a regression introduced in GCC 12.
Seems to be a library change in GCC 12 which triggers a pre-existing compiler
bug. This fails with all versions of GCC -std=c++20 but compiles with clang
-std=c++20 and EDG --c++20
namespace std
{
using size_t = decltype(sizeof(0));
template<typename _Tp, size_t _Nm>
struct array
{
_Tp _M_elems[_Nm];
constexpr const _Tp*
data() const noexcept
{ return _M_elems; }
};
template<typename _Tp>
constexpr
bool
__check_singular(_Tp* const& __ptr)
{ return __ptr == 0; }
template<typename _Tp, size_t _Nm>
constexpr
bool
operator==(const array<_Tp, _Nm>& __one, const array<_Tp, _Nm>& __two)
{
if (__check_singular(__one.data()))
throw 1;
return &__one == &__two;
}
}
struct P {
constexpr P(int i) : e{i} {}
bool operator==(P const &) const = default;
std::array<int, 1> e;
};
constexpr auto operator-(P lhs, P) { return lhs; }
constexpr P p{1}, q{0};
static_assert(p - q != 0);
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug c++/106212] Code becomes non-constexpr with _GLIBCXX_DEBUG
2022-07-06 8:17 [Bug c++/106212] New: Code becomes non-constexpr with _GLIBCXX_DEBUG fiesh at zefix dot tv
2022-07-06 8:19 ` [Bug c++/106212] " fiesh at zefix dot tv
2022-07-06 10:34 ` redi at gcc dot gnu.org
@ 2022-07-06 10:34 ` redi at gcc dot gnu.org
2022-07-06 10:37 ` redi at gcc dot gnu.org
3 siblings, 0 replies; 5+ messages in thread
From: redi at gcc dot gnu.org @ 2022-07-06 10:34 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106212
--- Comment #3 from Jonathan Wakely <redi at gcc dot gnu.org> ---
a.C:39:21: error: non-constant condition for static assertion
39 | static_assert(p - q != 0);
| ~~~~~~^~~~
a.C:39:24: in 'constexpr' expansion of 'operator-(p, q).P::operator==(P(0))'
a.C:34:8: in 'constexpr' expansion of 'std::operator==<int, 1>(((const
P*)this)->P::e, <anonymous>.P::e)'
a.C:19:20: error: '(((const int*)(&<anonymous>.P::e.std::array<int,
1>::_M_elems)) == 0)' is not a constant expression
19 | { return __ptr == 0; }
| ~~~~~~^~~~
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug c++/106212] Code becomes non-constexpr with _GLIBCXX_DEBUG
2022-07-06 8:17 [Bug c++/106212] New: Code becomes non-constexpr with _GLIBCXX_DEBUG fiesh at zefix dot tv
` (2 preceding siblings ...)
2022-07-06 10:34 ` redi at gcc dot gnu.org
@ 2022-07-06 10:37 ` redi at gcc dot gnu.org
3 siblings, 0 replies; 5+ messages in thread
From: redi at gcc dot gnu.org @ 2022-07-06 10:37 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106212
Jonathan Wakely <redi at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Resolution|--- |DUPLICATE
Status|NEW |RESOLVED
--- Comment #4 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Looks like a dup of PR 85944 since it only happens at global scope. The same
static_assert works fine in a function:
void f()
{
static_assert(p - q != 0);
}
*** This bug has been marked as a duplicate of bug 85944 ***
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2022-07-06 10:37 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-07-06 8:17 [Bug c++/106212] New: Code becomes non-constexpr with _GLIBCXX_DEBUG fiesh at zefix dot tv
2022-07-06 8:19 ` [Bug c++/106212] " fiesh at zefix dot tv
2022-07-06 10:34 ` redi at gcc dot gnu.org
2022-07-06 10:34 ` redi at gcc dot gnu.org
2022-07-06 10:37 ` 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).