public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libstdc++/111358] New: libstdc++'s optional::and_then and optional::transform are not ADL-proof
@ 2023-09-10  8:18 de34 at live dot cn
  2023-09-10  8:23 ` [Bug libstdc++/111358] " de34 at live dot cn
  0 siblings, 1 reply; 2+ messages in thread
From: de34 at live dot cn @ 2023-09-10  8:18 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 111358
           Summary: libstdc++'s optional::and_then and optional::transform
                    are not ADL-proof
           Product: gcc
           Version: 14.0
            Status: UNCONFIRMED
          Keywords: rejects-valid
          Severity: normal
          Priority: P3
         Component: libstdc++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: de34 at live dot cn
  Target Milestone: ---

The following program is incorrectly rejected when using libstdc++
(https://godbolt.org/z/eavTYjEdx):
```
#include <optional>

namespace fvs {
    struct Foo {};

    void operator*(std::optional<fvs::Foo>) = delete;
}

int main()
{
    std::optional<fvs::Foo>{}.and_then(
        [](auto&&){ return std::optional<char>{}; });
    std::optional<fvs::Foo>{}.transform(
        [](auto&&){ return 0; });
}
```

The reason of compilation error is that libstdc++ uses **this in and_then and
transform functions, which triggers ADL and finds unwanted operator*().

These monadic operations are currently specified in [optional.monadic] with
value(), so they should be ADL-proof.

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

* [Bug libstdc++/111358] libstdc++'s optional::and_then and optional::transform are not ADL-proof
  2023-09-10  8:18 [Bug libstdc++/111358] New: libstdc++'s optional::and_then and optional::transform are not ADL-proof de34 at live dot cn
@ 2023-09-10  8:23 ` de34 at live dot cn
  0 siblings, 0 replies; 2+ messages in thread
From: de34 at live dot cn @ 2023-09-10  8:23 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from Jiang An <de34 at live dot cn> ---
Related issues:

Monadic operations of expected are not ADL-proof per the uses of **this in
[expected.object.monadic]. However, currently implementations make them
ADL-proof by directly naming the union member, which is right IMO.

P2407R5 (https://wg21.link/p2407r5) is changing value() to **this in
[optional.monadic], which makes the monadic operations of optional not
ADL-proof. I believe this is a mistake.

I've mailed to LWG Chair to submit an LWG issue for these issues.

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

end of thread, other threads:[~2023-09-10  8:23 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-09-10  8:18 [Bug libstdc++/111358] New: libstdc++'s optional::and_then and optional::transform are not ADL-proof de34 at live dot cn
2023-09-10  8:23 ` [Bug libstdc++/111358] " 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).