Bug 51501 - [DR 1433] decltype over-agressive SFINAE
Summary: [DR 1433] decltype over-agressive SFINAE
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.7.0
: P3 normal
Target Milestone: 8.0
Assignee: Not yet assigned to anyone
URL:
Keywords: accepts-invalid
: 59481 61178 (view as bug list)
Depends on:
Blocks:
 
Reported: 2011-12-10 21:05 UTC by Dave Abrahams
Modified: 2022-02-01 22:48 UTC (History)
6 users (show)

See Also:
Host:
Target:
Build:
Known to work: 8.1.0
Known to fail: 7.5.0
Last reconfirmed: 2011-12-19 00:00:00


Attachments
test case (558 bytes, text/plain)
2011-12-10 21:06 UTC, Dave Abrahams
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Dave Abrahams 2011-12-10 21:05:20 UTC
Please see attached, which fails to compile.  If you compile with -DWORKAROUND you can "prove" to yourself that it ought to compile.
Comment 1 Dave Abrahams 2011-12-10 21:06:14 UTC
Created attachment 26045 [details]
test case

compile with -std=c++11 to see the failure.  Additionally add -DWORKAROUND to demonstrate why it ought to work.
Comment 2 Marc Glisse 2011-12-11 09:41:00 UTC
Could this be related to Bug 45873?
Comment 3 Dave Abrahams 2011-12-11 10:32:25 UTC
(In reply to comment #2)
> Could this be related to Bug 45873?

Not if your explanation in http://gcc.gnu.org/bugzilla/show_bug.cgi?id=45873#c2 is correct, I think.  This is a straightforward pack expansion with no change in the number of arguments.
Comment 4 Jason Merrill 2011-12-19 21:51:21 UTC
Reduced:

template <class T> T list(T x);

template <class H, class ...T>
auto list(H h, T ...args) -> decltype(list(args...));

auto list3 = list(1, 2, 3);
Comment 5 Jason Merrill 2011-12-19 22:06:03 UTC
The problem here is that the variadic 'list' is not in scope when the trailing-return-type is parsed.  3.3.2 says,

The point of declaration for a name is immediately after its complete declarator 

and the declarator includes the trailing-return-type.  And then since all the arguments are integers, no argument-dependent lookup is done, so the call in the trailing-return-type doesn't find the right template, and fails.

The versions of EDG and Clang that I have handy seem to reject this testcase on the same basis.

This seems like a flaw in the standard.
Comment 6 Dave Abrahams 2012-08-18 23:18:21 UTC
Jason, are you submitting (or is there already) an issue for this?
Comment 7 Jason Merrill 2012-12-15 04:08:09 UTC
This is core issue 1433, classified as an extension in Kona.  I don't know if EWG has taken a look at it yet.
Comment 8 Jonathan Wakely 2014-05-07 20:20:09 UTC
*** Bug 59481 has been marked as a duplicate of this bug. ***
Comment 9 Jason Merrill 2014-05-08 13:55:20 UTC
Ville, has EWG taken a look at this issue?  I'm sorry this didn't come up in the C++14 context, as it would have made sense to fix this when we were adding deduced return types.
Comment 10 Ville Voutilainen 2014-05-08 14:02:23 UTC
(In reply to Jason Merrill from comment #9)
> Ville, has EWG taken a look at this issue?  I'm sorry this didn't come up in

Not yet. The handling of Extension-status Core Issues was more or less
on hold while EWG was handling papers targeting C++14. I do intend to tell the EWG chair that we need to speed up the handling of such issues, they are
already in the EWG issues list, this particular one is
http://cplusplus.github.io/EWG/ewg-index.html#104

Wording and/or implementation experience would certainly be very welcome. ;)
Comment 11 Jonathan Wakely 2014-05-13 19:56:16 UTC
*** Bug 61178 has been marked as a duplicate of this bug. ***
Comment 12 Jonathan Wakely 2014-10-09 10:01:28 UTC
(In reply to Jason Merrill from comment #4)
> Reduced:
> 
> template <class T> T list(T x);
> 
> template <class H, class ...T>
> auto list(H h, T ...args) -> decltype(list(args...));
> 
> auto list3 = list(1, 2, 3);

Interestingly it works for (static or non-static) member functions:

struct X {
  template <class T> T list(T x);

  template <class H, class ...T>
  auto list(H h, T ...args) -> decltype(list(args...));
};

auto list3 = X{}.list(1, 2, 3);
Comment 13 Jonathan Wakely 2014-10-09 10:05:37 UTC
Also I guess we can unsuspend this and close as INVALID now that EWG rejected it.

And maybe issue a diagnostic for comment 12, as EDG and clang do?
Comment 14 Andrew Pinski 2021-12-10 07:21:47 UTC
(In reply to Jonathan Wakely from comment #13)
> And maybe issue a diagnostic for comment 12, as EDG and clang do?

We started to reject comment #12 in GCC 8+.
Comment 15 Martin Liška 2022-02-01 15:55:41 UTC
(In reply to Andrew Pinski from comment #14)
> (In reply to Jonathan Wakely from comment #13)
> > And maybe issue a diagnostic for comment 12, as EDG and clang do?
> 
> We started to reject comment #12 in GCC 8+.

It's rejected since r8-5270-g2b031ef48e365e25.
Comment 16 Jason Merrill 2022-02-01 22:48:24 UTC
Then this seems resolved, until/unless someone actually proposes to make it well-formed.