public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/64969] New: generic functions do not work with placeholder return types
@ 2015-02-07 15:33 rs2740 at gmail dot com
  2015-02-13 12:04 ` [Bug c++/64969] " redi at gcc dot gnu.org
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: rs2740 at gmail dot com @ 2015-02-07 15:33 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 64969
           Summary: generic functions do not work with placeholder return
                    types
           Product: gcc
           Version: 4.9.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: rs2740 at gmail dot com

GCC 4.9 added generic functions based on the draft Concepts Lite TS N3889.
(They now called abbreviated function templates.) However, the implementation
does not work with placeholder return types (including both deduced ones and
trailing return types).

For example, all three declarations

auto f1(auto x) { return x++; }
decltype(auto) f2(auto x) { return x++; }
auto f3(auto x) -> int { return x++; }

are apparently treated as if they were equivalent to

template<class T>
T f1(T x) { return x++; }
// etc.

rather than 

template<class T>
auto f1(T x) { return x++; }
// etc.

This is easily observable with

struct X {
    int operator++(int) const { return 0; }
};

f1(X());

which does not compile, complaining that int cannot be converted to X.


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

* [Bug c++/64969] generic functions do not work with placeholder return types
  2015-02-07 15:33 [Bug c++/64969] New: generic functions do not work with placeholder return types rs2740 at gmail dot com
@ 2015-02-13 12:04 ` redi at gcc dot gnu.org
  2015-02-13 12:07 ` redi at gcc dot gnu.org
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: redi at gcc dot gnu.org @ 2015-02-13 12:04 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |rejects-valid
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2015-02-13
     Ever confirmed|0                           |1

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

auto f1(auto x) { return x++; }
decltype(auto) f2(auto x) { return x++; }
auto f3(auto x) -> int { return x++; }

struct X {
  int operator++(int) const { return 0; }
};

X x;
auto r1 = f1(x);
auto r2 = f2(x);
auto r3 = f3(x);


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

* [Bug c++/64969] generic functions do not work with placeholder return types
  2015-02-07 15:33 [Bug c++/64969] New: generic functions do not work with placeholder return types rs2740 at gmail dot com
  2015-02-13 12:04 ` [Bug c++/64969] " redi at gcc dot gnu.org
@ 2015-02-13 12:07 ` redi at gcc dot gnu.org
  2015-02-20 11:24 ` harald at gigawatt dot nl
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: redi at gcc dot gnu.org @ 2015-02-13 12:07 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Or even simpler:

auto f1(auto x) { return *x; }
decltype(auto) f2(auto x) { return *x; }
auto f3(auto x) -> int { return *x; }

int i;
auto r1 = f1(&i);
auto r2 = f2(&i);
auto r3 = f3(&i);


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

* [Bug c++/64969] generic functions do not work with placeholder return types
  2015-02-07 15:33 [Bug c++/64969] New: generic functions do not work with placeholder return types rs2740 at gmail dot com
  2015-02-13 12:04 ` [Bug c++/64969] " redi at gcc dot gnu.org
  2015-02-13 12:07 ` redi at gcc dot gnu.org
@ 2015-02-20 11:24 ` harald at gigawatt dot nl
  2015-07-25  7:14 ` jason at gcc dot gnu.org
  2015-07-25  7:15 ` jason at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: harald at gigawatt dot nl @ 2015-02-20 11:24 UTC (permalink / raw)
  To: gcc-bugs

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

Harald van Dijk <harald at gigawatt dot nl> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |harald at gigawatt dot nl

--- Comment #3 from Harald van Dijk <harald at gigawatt dot nl> ---
This happens because auto is encoded as a template parameter that is one level
deeper than the currently deepest real template parameter. In other words,
  auto f()
is encoded as
  <<template-param-1-1>> f(),
and
  template <typename T> auto f()
is encoded as
  template <typename T> <<template-param-2-1>> f().

Given
  auto f1(auto x),
when the first auto is parsed, it becomes
  <<template-param-1-1>> f1(auto x).
When the second auto is parsed, and the function implicitly becomes a template,
it looks like
  template <typename <<auto>> > <<template-param-1-1>>
f1(<<template-param-1-1>> x)
where the first <<template-param-1-1>> should be <<template-param-2-1>>.

Instead of fixing up existing references to auto when a function is implicitly
made a template, how about encoding auto as a template argument with a level of
zero, and adding a tf_auto flag for tsubst to specify that auto is to be
replaced? If that flag is specified, fix up the zero by changing it to
(processing_template_decl+1), if that flag is not specified, leave auto alone.
All that seems to be needed aside from that, in a quick test, is making
reduce_template_parm_level aware of them, making it leave a level of zero at
zero. The cases in this bug pass, and manually running tests on
gcc/testsuite/g++.dg/cpp1y/auto* doesn't show problems either. I'll do some
more extensive testing, and also run the full test suite.


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

* [Bug c++/64969] generic functions do not work with placeholder return types
  2015-02-07 15:33 [Bug c++/64969] New: generic functions do not work with placeholder return types rs2740 at gmail dot com
                   ` (2 preceding siblings ...)
  2015-02-20 11:24 ` harald at gigawatt dot nl
@ 2015-07-25  7:14 ` jason at gcc dot gnu.org
  2015-07-25  7:15 ` jason at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: jason at gcc dot gnu.org @ 2015-07-25  7:14 UTC (permalink / raw)
  To: gcc-bugs

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

Jason Merrill <jason at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |jason at gcc dot gnu.org
         Resolution|---                         |FIXED
           Assignee|unassigned at gcc dot gnu.org      |jason at gcc dot gnu.org
   Target Milestone|---                         |6.0

--- Comment #5 from Jason Merrill <jason at gcc dot gnu.org> ---
Fixed for GCC 6.


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

* [Bug c++/64969] generic functions do not work with placeholder return types
  2015-02-07 15:33 [Bug c++/64969] New: generic functions do not work with placeholder return types rs2740 at gmail dot com
                   ` (3 preceding siblings ...)
  2015-07-25  7:14 ` jason at gcc dot gnu.org
@ 2015-07-25  7:15 ` jason at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: jason at gcc dot gnu.org @ 2015-07-25  7:15 UTC (permalink / raw)
  To: gcc-bugs

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

Jason Merrill <jason at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |bruno.manga95 at gmail dot com

--- Comment #6 from Jason Merrill <jason at gcc dot gnu.org> ---
*** Bug 66266 has been marked as a duplicate of this bug. ***


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

end of thread, other threads:[~2015-07-25  7:15 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-02-07 15:33 [Bug c++/64969] New: generic functions do not work with placeholder return types rs2740 at gmail dot com
2015-02-13 12:04 ` [Bug c++/64969] " redi at gcc dot gnu.org
2015-02-13 12:07 ` redi at gcc dot gnu.org
2015-02-20 11:24 ` harald at gigawatt dot nl
2015-07-25  7:14 ` jason at gcc dot gnu.org
2015-07-25  7:15 ` jason 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).