public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libstdc++/115059] New: Constraints/Mandates on the comparison operators of std::optional and std::variant are overly strict
@ 2024-05-13 1:57 de34 at live dot cn
2024-05-13 9:06 ` [Bug libstdc++/115059] " redi at gcc dot gnu.org
2024-05-13 9:47 ` de34 at live dot cn
0 siblings, 2 replies; 3+ messages in thread
From: de34 at live dot cn @ 2024-05-13 1:57 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115059
Bug ID: 115059
Summary: Constraints/Mandates on the comparison operators of
std::optional and std::variant are overly strict
Product: gcc
Version: 15.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: libstdc++
Assignee: unassigned at gcc dot gnu.org
Reporter: de34 at live dot cn
Target Milestone: ---
The following example should compile in C++23/26 (or some other modes where
explicit object parameters are available) due to CWG DR 2813
(https://cplusplus.github.io/CWG/issues/2813.html), given that
[optional.relops] and [variant.relops] only require the result to be
convertible to bool.
```
#include <optional>
#include <variant>
class PinnedBoolean {
private:
bool val_;
PinnedBoolean(const PinnedBoolean&) = delete;
PinnedBoolean& operator=(const PinnedBoolean&) = delete;
public:
constexpr explicit PinnedBoolean(bool b) noexcept : val_{b} {}
constexpr operator bool(this PinnedBoolean x) noexcept { return x.val_; }
};
static_assert(PinnedBoolean{true});
struct X {
friend constexpr PinnedBoolean operator==(X, X) noexcept { return
PinnedBoolean{true}; }
friend constexpr PinnedBoolean operator!=(X, X) noexcept { return
PinnedBoolean{false}; }
};
static_assert(std::optional<X>{} == std::optional<X>{});
static_assert(std::variant<X>{} == std::variant<X>{});
```
However, libc++ is currently applying stricter requirements
(https://godbolt.org/z/Mc3bse5h7).
Since CWG2813, both __boolean_testable and is_convertible_v are stricter than
the plain "convertible to", because the implicit conversion from the result
type to bool can be only well-formed for prvalues but not xvalues.
^ permalink raw reply [flat|nested] 3+ messages in thread
* [Bug libstdc++/115059] Constraints/Mandates on the comparison operators of std::optional and std::variant are overly strict
2024-05-13 1:57 [Bug libstdc++/115059] New: Constraints/Mandates on the comparison operators of std::optional and std::variant are overly strict de34 at live dot cn
@ 2024-05-13 9:06 ` redi at gcc dot gnu.org
2024-05-13 9:47 ` de34 at live dot cn
1 sibling, 0 replies; 3+ messages in thread
From: redi at gcc dot gnu.org @ 2024-05-13 9:06 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115059
--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> ---
I don't want to change anything in libstdc++ here. Either std::is_convertible
should be sufficient to check "convertible to" constraints, or "convertible to"
should exclude these kind of games.
^ permalink raw reply [flat|nested] 3+ messages in thread
* [Bug libstdc++/115059] Constraints/Mandates on the comparison operators of std::optional and std::variant are overly strict
2024-05-13 1:57 [Bug libstdc++/115059] New: Constraints/Mandates on the comparison operators of std::optional and std::variant are overly strict de34 at live dot cn
2024-05-13 9:06 ` [Bug libstdc++/115059] " redi at gcc dot gnu.org
@ 2024-05-13 9:47 ` de34 at live dot cn
1 sibling, 0 replies; 3+ messages in thread
From: de34 at live dot cn @ 2024-05-13 9:47 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115059
--- Comment #2 from Jiang An <de34 at live dot cn> ---
(In reply to Jonathan Wakely from comment #1)
> I don't want to change anything in libstdc++ here. Either
> std::is_convertible should be sufficient to check "convertible to"
> constraints, or "convertible to" should exclude these kind of games.
Yeah. This is perphaps in the scope of LWG484 and LWG3105, but guaranteed copy
elision doesn't seem discussed yet.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2024-05-13 9:47 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-05-13 1:57 [Bug libstdc++/115059] New: Constraints/Mandates on the comparison operators of std::optional and std::variant are overly strict de34 at live dot cn
2024-05-13 9:06 ` [Bug libstdc++/115059] " redi at gcc dot gnu.org
2024-05-13 9:47 ` de34 at live dot cn
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).