public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libstdc++/94890] New: std::tuple<aggregate>({0}) fails to compile with -std=c++2a
@ 2020-04-30 14:32 ppalka at gcc dot gnu.org
  2020-04-30 22:19 ` [Bug c++/94890] " ppalka at gcc dot gnu.org
                   ` (8 more replies)
  0 siblings, 9 replies; 10+ messages in thread
From: ppalka at gcc dot gnu.org @ 2020-04-30 14:32 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 94890
           Summary: std::tuple<aggregate>({0}) fails to compile with
                    -std=c++2a
           Product: gcc
           Version: 10.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libstdc++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: ppalka at gcc dot gnu.org
  Target Milestone: ---

$ cat testcase.C
#include <tuple>

struct c { int i; };

std::tuple<c> x({0});

$ g++-10 -std=c++17 testcase.C
$ g++-10 -std=c++2a testcase.C
testcase.C:5:20: error: converting to ‘std::tuple<c>’ from initializer list
would use explicit constructor ‘constexpr
std::tuple<_Elements>::tuple(_UElements&& ...) [with _UElements = {int}; bool
_Valid = true; typename
std::enable_if<std::tuple<_Elements>::_TCC<_Valid>::__is_explicitly_constructible<_UElements
...>(), bool>::type <anonymous> = false; _Elements = {c}]’
    5 | std::tuple<c> x({0});
      |                    ^


PR94885 may be related, but its testcase wasn't reduced from this testcase.

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

* [Bug c++/94890] std::tuple<aggregate>({0}) fails to compile with -std=c++2a
  2020-04-30 14:32 [Bug libstdc++/94890] New: std::tuple<aggregate>({0}) fails to compile with -std=c++2a ppalka at gcc dot gnu.org
@ 2020-04-30 22:19 ` ppalka at gcc dot gnu.org
  2020-04-30 23:01 ` ppalka at gcc dot gnu.org
                   ` (7 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: ppalka at gcc dot gnu.org @ 2020-04-30 22:19 UTC (permalink / raw)
  To: gcc-bugs

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

Patrick Palka <ppalka at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
          Component|libstdc++                   |c++

--- Comment #1 from Patrick Palka <ppalka at gcc dot gnu.org> ---
Bisection seems to be pointing to r10-6519, so changing component from
libstdc++ to c++.

A reduced testcase:

template <int a> struct b { static const int c = a; };
template <int> struct d;
template <> struct d<0> { typedef int e; };
struct f {};
template <class g, class = decltype(g(0))> f aa(int);
template <class> b<0> aa(...);
struct h {
  int i;
};
template <class...> struct j : decltype(aa<h>(0)) {};
template <bool> using ap = b<1>;
template <template <class...> class aq> ap<typename d<aq<>::c>::e{}> at(int);
template <template <class> class> b<0> at(...);
struct k {
  template <class> static const int ax = decltype(at<j>(0))::c;
  k(...);
  template <class l, typename d<ax<l>>::e = 0> explicit k(l);
};

k a({0});

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

* [Bug c++/94890] std::tuple<aggregate>({0}) fails to compile with -std=c++2a
  2020-04-30 14:32 [Bug libstdc++/94890] New: std::tuple<aggregate>({0}) fails to compile with -std=c++2a ppalka at gcc dot gnu.org
  2020-04-30 22:19 ` [Bug c++/94890] " ppalka at gcc dot gnu.org
@ 2020-04-30 23:01 ` ppalka at gcc dot gnu.org
  2020-04-30 23:13 ` ppalka at gcc dot gnu.org
                   ` (6 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: ppalka at gcc dot gnu.org @ 2020-04-30 23:01 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Patrick Palka <ppalka at gcc dot gnu.org> ---
Minimal testcase:


template <class e, class = decltype(e(0))>
void foo();

struct t { int a; };

void bar()
{
  foo<t>();
}

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

* [Bug c++/94890] std::tuple<aggregate>({0}) fails to compile with -std=c++2a
  2020-04-30 14:32 [Bug libstdc++/94890] New: std::tuple<aggregate>({0}) fails to compile with -std=c++2a ppalka at gcc dot gnu.org
  2020-04-30 22:19 ` [Bug c++/94890] " ppalka at gcc dot gnu.org
  2020-04-30 23:01 ` ppalka at gcc dot gnu.org
@ 2020-04-30 23:13 ` ppalka at gcc dot gnu.org
  2020-05-01  2:59 ` mpolacek at gcc dot gnu.org
                   ` (5 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: ppalka at gcc dot gnu.org @ 2020-04-30 23:13 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from Patrick Palka <ppalka at gcc dot gnu.org> ---
Whoops, the above minimal testcase doesn't actually illustrate any bug, we just
correctly accept it in c++2a mode ever since r10-6519.  Hmm...

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

* [Bug c++/94890] std::tuple<aggregate>({0}) fails to compile with -std=c++2a
  2020-04-30 14:32 [Bug libstdc++/94890] New: std::tuple<aggregate>({0}) fails to compile with -std=c++2a ppalka at gcc dot gnu.org
                   ` (2 preceding siblings ...)
  2020-04-30 23:13 ` ppalka at gcc dot gnu.org
@ 2020-05-01  2:59 ` mpolacek at gcc dot gnu.org
  2020-05-01 14:28 ` ville.voutilainen at gmail dot com
                   ` (4 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2020-05-01  2:59 UTC (permalink / raw)
  To: gcc-bugs

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

Marek Polacek <mpolacek at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |mpolacek at gcc dot gnu.org

--- Comment #4 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
My current theory is that it is not a bug.

While processing "decltype(aa<h>(0))" we look for a suitable aa candidate, and
thanks to C++20 paren-init "g(0)" in "decltype(g(0))" succeeds.  Then we select
 aa(int) rather than aa(...) and due to various SFINAEs we end up choosing the
explicit k(l) constructor.  In C++17 the paren-init doesn't kick in and we
select "k(...)".  So in C++20 when actually converting {0} to S we hit:

 7426         /* When converting from an init list we consider explicit
 7427            constructors, but actually trying to call one is an error.  */

(DR 1518 + DR 1630)

This fails in C++17 too when

template <class g, class = decltype(g(0))> f aa(int);

is changed to

template <class g, class = decltype(g{0})> f aa(int);

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

* [Bug c++/94890] std::tuple<aggregate>({0}) fails to compile with -std=c++2a
  2020-04-30 14:32 [Bug libstdc++/94890] New: std::tuple<aggregate>({0}) fails to compile with -std=c++2a ppalka at gcc dot gnu.org
                   ` (3 preceding siblings ...)
  2020-05-01  2:59 ` mpolacek at gcc dot gnu.org
@ 2020-05-01 14:28 ` ville.voutilainen at gmail dot com
  2020-05-01 14:33 ` mpolacek at gcc dot gnu.org
                   ` (3 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: ville.voutilainen at gmail dot com @ 2020-05-01 14:28 UTC (permalink / raw)
  To: gcc-bugs

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

Ville Voutilainen <ville.voutilainen at gmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Assignee|unassigned at gcc dot gnu.org      |ville.voutilainen at gmail dot com
                 CC|                            |ville.voutilainen at gmail dot com
   Last reconfirmed|                            |2020-05-01
     Ever confirmed|0                           |1
             Status|UNCONFIRMED                 |ASSIGNED

--- Comment #5 from Ville Voutilainen <ville.voutilainen at gmail dot com> ---
What happens with std::tuple<c> x({0}) is that the _UElements&&... constructor
is not a direct candidate, so we fall back to trying a copy constructor. That's
a match, and then it tries to convert the argument. Since c is constructible
from int, but not convertible from int, the match is the explicit constructor,
and calling that fails because initializing the argument is copy-init.

The fix that we can apply in tuple is to make __is_implicitly_constructible
look at either is_convertible or is_aggregate, and then negate properly
in __is_explicitly_constructible.

In other words, mine. :)

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

* [Bug c++/94890] std::tuple<aggregate>({0}) fails to compile with -std=c++2a
  2020-04-30 14:32 [Bug libstdc++/94890] New: std::tuple<aggregate>({0}) fails to compile with -std=c++2a ppalka at gcc dot gnu.org
                   ` (4 preceding siblings ...)
  2020-05-01 14:28 ` ville.voutilainen at gmail dot com
@ 2020-05-01 14:33 ` mpolacek at gcc dot gnu.org
  2020-05-01 14:46 ` ville.voutilainen at gmail dot com
                   ` (2 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2020-05-01 14:33 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #6 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Thanks Ville.  What I should have said...

(In reply to Marek Polacek from comment #4)
> My current theory is that it is not a bug.

...in the compiler proper.  It'd be nice if the original test compiled.

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

* [Bug c++/94890] std::tuple<aggregate>({0}) fails to compile with -std=c++2a
  2020-04-30 14:32 [Bug libstdc++/94890] New: std::tuple<aggregate>({0}) fails to compile with -std=c++2a ppalka at gcc dot gnu.org
                   ` (5 preceding siblings ...)
  2020-05-01 14:33 ` mpolacek at gcc dot gnu.org
@ 2020-05-01 14:46 ` ville.voutilainen at gmail dot com
  2020-05-01 14:47 ` ville.voutilainen at gmail dot com
  2020-09-27 19:24 ` [Bug libstdc++/94890] " ville.voutilainen at gmail dot com
  8 siblings, 0 replies; 10+ messages in thread
From: ville.voutilainen at gmail dot com @ 2020-05-01 14:46 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #7 from Ville Voutilainen <ville.voutilainen at gmail dot com> ---
..and as expected, std::optional is broken the same way.

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

* [Bug c++/94890] std::tuple<aggregate>({0}) fails to compile with -std=c++2a
  2020-04-30 14:32 [Bug libstdc++/94890] New: std::tuple<aggregate>({0}) fails to compile with -std=c++2a ppalka at gcc dot gnu.org
                   ` (6 preceding siblings ...)
  2020-05-01 14:46 ` ville.voutilainen at gmail dot com
@ 2020-05-01 14:47 ` ville.voutilainen at gmail dot com
  2020-09-27 19:24 ` [Bug libstdc++/94890] " ville.voutilainen at gmail dot com
  8 siblings, 0 replies; 10+ messages in thread
From: ville.voutilainen at gmail dot com @ 2020-05-01 14:47 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #8 from Ville Voutilainen <ville.voutilainen at gmail dot com> ---
(In reply to Marek Polacek from comment #6)
> Thanks Ville.  What I should have said...
> 
> (In reply to Marek Polacek from comment #4)
> > My current theory is that it is not a bug.
> 
> ...in the compiler proper.  It'd be nice if the original test compiled.

No worries. This needs two library fixes and an LWG issue, I'll take care of
it.

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

* [Bug libstdc++/94890] std::tuple<aggregate>({0}) fails to compile with -std=c++2a
  2020-04-30 14:32 [Bug libstdc++/94890] New: std::tuple<aggregate>({0}) fails to compile with -std=c++2a ppalka at gcc dot gnu.org
                   ` (7 preceding siblings ...)
  2020-05-01 14:47 ` ville.voutilainen at gmail dot com
@ 2020-09-27 19:24 ` ville.voutilainen at gmail dot com
  8 siblings, 0 replies; 10+ messages in thread
From: ville.voutilainen at gmail dot com @ 2020-09-27 19:24 UTC (permalink / raw)
  To: gcc-bugs

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

Ville Voutilainen <ville.voutilainen at gmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
         Resolution|---                         |INVALID

--- Comment #9 from Ville Voutilainen <ville.voutilainen at gmail dot com> ---
LEWG says NO: https://cplusplus.github.io/LWG/issue3440

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

end of thread, other threads:[~2020-09-27 19:24 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-04-30 14:32 [Bug libstdc++/94890] New: std::tuple<aggregate>({0}) fails to compile with -std=c++2a ppalka at gcc dot gnu.org
2020-04-30 22:19 ` [Bug c++/94890] " ppalka at gcc dot gnu.org
2020-04-30 23:01 ` ppalka at gcc dot gnu.org
2020-04-30 23:13 ` ppalka at gcc dot gnu.org
2020-05-01  2:59 ` mpolacek at gcc dot gnu.org
2020-05-01 14:28 ` ville.voutilainen at gmail dot com
2020-05-01 14:33 ` mpolacek at gcc dot gnu.org
2020-05-01 14:46 ` ville.voutilainen at gmail dot com
2020-05-01 14:47 ` ville.voutilainen at gmail dot com
2020-09-27 19:24 ` [Bug libstdc++/94890] " ville.voutilainen at gmail dot com

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).