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

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