public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/47999] New: [C++0x] auto type deduction works incorrectly in a function template
@ 2011-03-05 17:28 mimomorin at gmail dot com
  2011-03-05 23:39 ` [Bug c++/47999] " paolo.carlini at oracle dot com
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: mimomorin at gmail dot com @ 2011-03-05 17:28 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47999

           Summary: [C++0x] auto type deduction works incorrectly in a
                    function template
           Product: gcc
           Version: 4.6.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: mimomorin@gmail.com


Created attachment 23554
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=23554
Test case

When `auto&&` is initialized with a function return value that is an lvalue
reference, the deduced type should be an lvalue reference. 

    int& identity(int& i) { return i; }

    void f()
    {
        int i = 0;
        auto&& x = identity(i); // x has type `int&`
    }

But, in a function template, auto type deduction incorrectly deduces
the type as an rvalue reference. 

    template <typename T>
    void f()
    {
        int i = 0;
        auto&& x = identity(i); // BUG: x has type `int&&`
    }

This bug leads to compilation error in gcc 4.5 and 4.6, 
because lvalues cannot bind to rvalue references. 
In gcc 4.4, the code compiles fine because lvalues are 
allowed to bind to rvalue references.

Tested compilers: gcc-4.4.5, 4.5.2, 4.6-20110219.
(This problem was found by Nathan Ridge.)


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

* [Bug c++/47999] [C++0x] auto type deduction works incorrectly in a function template
  2011-03-05 17:28 [Bug c++/47999] New: [C++0x] auto type deduction works incorrectly in a function template mimomorin at gmail dot com
@ 2011-03-05 23:39 ` paolo.carlini at oracle dot com
  2011-03-08 13:47 ` jason at gcc dot gnu.org
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: paolo.carlini at oracle dot com @ 2011-03-05 23:39 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47999

Paolo Carlini <paolo.carlini at oracle dot com> changed:

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

--- Comment #1 from Paolo Carlini <paolo.carlini at oracle dot com> 2011-03-05 23:39:18 UTC ---
Let's CC Jason,


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

* [Bug c++/47999] [C++0x] auto type deduction works incorrectly in a function template
  2011-03-05 17:28 [Bug c++/47999] New: [C++0x] auto type deduction works incorrectly in a function template mimomorin at gmail dot com
  2011-03-05 23:39 ` [Bug c++/47999] " paolo.carlini at oracle dot com
@ 2011-03-08 13:47 ` jason at gcc dot gnu.org
  2011-03-08 15:14 ` jason at gcc dot gnu.org
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: jason at gcc dot gnu.org @ 2011-03-08 13:47 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47999

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |ASSIGNED
   Last reconfirmed|                            |2011.03.08 13:47:09
         AssignedTo|unassigned at gcc dot       |jason at gcc dot gnu.org
                   |gnu.org                     |
     Ever Confirmed|0                           |1


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

* [Bug c++/47999] [C++0x] auto type deduction works incorrectly in a function template
  2011-03-05 17:28 [Bug c++/47999] New: [C++0x] auto type deduction works incorrectly in a function template mimomorin at gmail dot com
  2011-03-05 23:39 ` [Bug c++/47999] " paolo.carlini at oracle dot com
  2011-03-08 13:47 ` jason at gcc dot gnu.org
@ 2011-03-08 15:14 ` jason at gcc dot gnu.org
  2011-03-16 17:22 ` jason at gcc dot gnu.org
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: jason at gcc dot gnu.org @ 2011-03-08 15:14 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47999

--- Comment #2 from Jason Merrill <jason at gcc dot gnu.org> 2011-03-08 15:14:02 UTC ---
Created attachment 23583
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=23583
Fix

Here's a patch that fixes the bug and passes regression testing.  I don't plan
to put it in for 4.6.0 as I'm concerned about possible side-effects; I seem to
remember trying to do exactly this once before and it causing problems.  I'll
put it in for 4.7 once 4.6 branches, and then perhaps into 4.6.1.


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

* [Bug c++/47999] [C++0x] auto type deduction works incorrectly in a function template
  2011-03-05 17:28 [Bug c++/47999] New: [C++0x] auto type deduction works incorrectly in a function template mimomorin at gmail dot com
                   ` (2 preceding siblings ...)
  2011-03-08 15:14 ` jason at gcc dot gnu.org
@ 2011-03-16 17:22 ` jason at gcc dot gnu.org
  2011-03-29 14:30 ` jason at gcc dot gnu.org
  2011-03-29 14:56 ` jason at gcc dot gnu.org
  5 siblings, 0 replies; 7+ messages in thread
From: jason at gcc dot gnu.org @ 2011-03-16 17:22 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47999

--- Comment #3 from Jason Merrill <jason at gcc dot gnu.org> 2011-03-16 17:04:35 UTC ---
Author: jason
Date: Wed Mar 16 17:04:30 2011
New Revision: 171053

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=171053
Log:
    PR c++/47999
    * semantics.c (finish_call_expr): Preserve reference semantics
    in templates.

Added:
    trunk/gcc/testsuite/g++.dg/cpp0x/auto22.C
Modified:
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/semantics.c
    trunk/gcc/testsuite/ChangeLog


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

* [Bug c++/47999] [C++0x] auto type deduction works incorrectly in a function template
  2011-03-05 17:28 [Bug c++/47999] New: [C++0x] auto type deduction works incorrectly in a function template mimomorin at gmail dot com
                   ` (3 preceding siblings ...)
  2011-03-16 17:22 ` jason at gcc dot gnu.org
@ 2011-03-29 14:30 ` jason at gcc dot gnu.org
  2011-03-29 14:56 ` jason at gcc dot gnu.org
  5 siblings, 0 replies; 7+ messages in thread
From: jason at gcc dot gnu.org @ 2011-03-29 14:30 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47999

--- Comment #4 from Jason Merrill <jason at gcc dot gnu.org> 2011-03-29 14:25:49 UTC ---
Author: jason
Date: Tue Mar 29 14:25:37 2011
New Revision: 171670

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=171670
Log:
    PR c++/47999
    * semantics.c (finish_call_expr): Preserve reference semantics
    in templates.

Added:
    branches/gcc-4_6-branch/gcc/testsuite/g++.dg/cpp0x/auto22.C
Modified:
    branches/gcc-4_6-branch/gcc/cp/ChangeLog
    branches/gcc-4_6-branch/gcc/cp/semantics.c
    branches/gcc-4_6-branch/gcc/testsuite/ChangeLog


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

* [Bug c++/47999] [C++0x] auto type deduction works incorrectly in a function template
  2011-03-05 17:28 [Bug c++/47999] New: [C++0x] auto type deduction works incorrectly in a function template mimomorin at gmail dot com
                   ` (4 preceding siblings ...)
  2011-03-29 14:30 ` jason at gcc dot gnu.org
@ 2011-03-29 14:56 ` jason at gcc dot gnu.org
  5 siblings, 0 replies; 7+ messages in thread
From: jason at gcc dot gnu.org @ 2011-03-29 14:56 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47999

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
         Resolution|                            |FIXED
   Target Milestone|---                         |4.6.1

--- Comment #5 from Jason Merrill <jason at gcc dot gnu.org> 2011-03-29 14:38:30 UTC ---
Fixed for 4.6.1.


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

end of thread, other threads:[~2011-03-29 14:38 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-03-05 17:28 [Bug c++/47999] New: [C++0x] auto type deduction works incorrectly in a function template mimomorin at gmail dot com
2011-03-05 23:39 ` [Bug c++/47999] " paolo.carlini at oracle dot com
2011-03-08 13:47 ` jason at gcc dot gnu.org
2011-03-08 15:14 ` jason at gcc dot gnu.org
2011-03-16 17:22 ` jason at gcc dot gnu.org
2011-03-29 14:30 ` jason at gcc dot gnu.org
2011-03-29 14:56 ` 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).