public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/114898] New: Converting {} to a tag type should be ill-formed SFINAE-friendly
@ 2024-04-30 14:47 arthur.j.odwyer at gmail dot com
  2024-04-30 15:00 ` [Bug c++/114898] " redi at gcc dot gnu.org
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: arthur.j.odwyer at gmail dot com @ 2024-04-30 14:47 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 114898
           Summary: Converting {} to a tag type should be ill-formed
                    SFINAE-friendly
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: arthur.j.odwyer at gmail dot com
  Target Milestone: ---

See LWG 2510, "Tag types should not be DefaultConstructible":
https://cplusplus.github.io/LWG/issue2510

WG21 seems convinced that there's also a core-language issue here:
https://cplusplus.github.io/CWG/issues/1518.html

In the notes for LWG2510, I see:
> JW [i.e. jwakely] explains that it's important that tag types cannot be constructed from "{}" (e.g. the allocator tag in the tuple constructors).

However, it looks like GCC+libstdc++ violates LWG2510 by allowing tag types to
be constructible from `{}` (or at least to fail in a SFINAE-unfriendly way).

    // https://godbolt.org/z/cMzar8Ehf
    struct Widget {
      int i[1];
    };
    std::optional<Widget> r1( {{}} );
      // Bug 1: GCC complains about nullopt_t's explicit ctor
    std::optional<Widget> r2{ {} };
      // Bug 2: GCC complains about in_place_t's explicit ctor

Now, according to Clang+libstdc++, Clang+libc++, and MSVC+STL, both examples
should be well-formed, and should mean:

- r1 is direct-initialized from {{}} i.e. a Widget with one element {} i.e. a
value-initialized array of int[1].

- r2 is direct-list-initialized from {} i.e. a value-initialized Widget.

In the April 2024 WG21 mailing, Brian Bi brings a paper P3112 "Specify
Constructor of std::nullopt_t" motivated by this bad behavior of GCC's,
https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2024/p3112r0.html
but really I think it should just be a bug report, since GCC is the one
compiler currently misbehaving, and jwakely was already quoted above as wanting
`{}` _not_ to construct a tag type.

I don't much care whether this is treated as a GCC compiler bug or a libstdc++
library bug, but at first glance it _looks_ like a compiler bug (since
libstdc++ works fine with Clang). If it _is_ treated as a libstdc++ bug, you
might take this opportunity to audit all of the tag types in the entire library
and just make sure they're all implemented using the same consistent technique,
whatever it is.

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

* [Bug c++/114898] Converting {} to a tag type should be ill-formed SFINAE-friendly
  2024-04-30 14:47 [Bug c++/114898] New: Converting {} to a tag type should be ill-formed SFINAE-friendly arthur.j.odwyer at gmail dot com
@ 2024-04-30 15:00 ` redi at gcc dot gnu.org
  2024-04-30 15:06 ` redi at gcc dot gnu.org
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: redi at gcc dot gnu.org @ 2024-04-30 15:00 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Standalone testcase:

struct nullopt_t {
    enum class Hidden { Token };
    explicit constexpr nullopt_t(Hidden) noexcept { }
};

struct in_place_t {
    explicit constexpr in_place_t() = default;
};

template<typename T>
struct optional
{
    template<typename U = T>
    optional(U&&) { }

    optional(in_place_t);

    optional(nullopt_t);
};

struct Widget {
    int i[1];
};

optional<Widget> r1( {{}} );

optional<Widget> r2{ {} };

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

* [Bug c++/114898] Converting {} to a tag type should be ill-formed SFINAE-friendly
  2024-04-30 14:47 [Bug c++/114898] New: Converting {} to a tag type should be ill-formed SFINAE-friendly arthur.j.odwyer at gmail dot com
  2024-04-30 15:00 ` [Bug c++/114898] " redi at gcc dot gnu.org
@ 2024-04-30 15:06 ` redi at gcc dot gnu.org
  2024-05-02  9:23 ` redi at gcc dot gnu.org
  2024-05-02  9:24 ` redi at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: redi at gcc dot gnu.org @ 2024-04-30 15:06 UTC (permalink / raw)
  To: gcc-bugs

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

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
     Ever confirmed|0                           |1
   Last reconfirmed|                            |2024-04-30
           See Also|                            |https://gcc.gnu.org/bugzill
                   |                            |a/show_bug.cgi?id=113300
             Status|UNCONFIRMED                 |NEW

--- Comment #2 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Might be related to Bug 113300 and/or Bug 102257

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

* [Bug c++/114898] Converting {} to a tag type should be ill-formed SFINAE-friendly
  2024-04-30 14:47 [Bug c++/114898] New: Converting {} to a tag type should be ill-formed SFINAE-friendly arthur.j.odwyer at gmail dot com
  2024-04-30 15:00 ` [Bug c++/114898] " redi at gcc dot gnu.org
  2024-04-30 15:06 ` redi at gcc dot gnu.org
@ 2024-05-02  9:23 ` redi at gcc dot gnu.org
  2024-05-02  9:24 ` redi at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: redi at gcc dot gnu.org @ 2024-05-02  9:23 UTC (permalink / raw)
  To: gcc-bugs

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

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|---                         |DUPLICATE

--- Comment #3 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Dup of Bug 102257, which might be what CWG 2586 says should happen, sadly.

*** This bug has been marked as a duplicate of bug 102257 ***

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

* [Bug c++/114898] Converting {} to a tag type should be ill-formed SFINAE-friendly
  2024-04-30 14:47 [Bug c++/114898] New: Converting {} to a tag type should be ill-formed SFINAE-friendly arthur.j.odwyer at gmail dot com
                   ` (2 preceding siblings ...)
  2024-05-02  9:23 ` redi at gcc dot gnu.org
@ 2024-05-02  9:24 ` redi at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: redi at gcc dot gnu.org @ 2024-05-02  9:24 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from Jonathan Wakely <redi at gcc dot gnu.org> ---
(In reply to Jonathan Wakely from comment #3)
> Dup of Bug 102257, which might be what CWG 2586 says should happen, sadly.

Oops 2856

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

end of thread, other threads:[~2024-05-02  9:24 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-04-30 14:47 [Bug c++/114898] New: Converting {} to a tag type should be ill-formed SFINAE-friendly arthur.j.odwyer at gmail dot com
2024-04-30 15:00 ` [Bug c++/114898] " redi at gcc dot gnu.org
2024-04-30 15:06 ` redi at gcc dot gnu.org
2024-05-02  9:23 ` redi at gcc dot gnu.org
2024-05-02  9:24 ` 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).