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

             Bug #: 53223
           Summary: [c++0x] auto&& and operator* don't mix inside
                    templates
    Classification: Unclassified
           Product: gcc
           Version: 4.7.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassig...@gcc.gnu.org
        ReportedBy: l...@mit.edu


This is truly bizarre:

struct A
{
  int good() const;
  int operator *() const;
};

template<typename T>
void func(T t)
{
  A x;
  auto &&g1 = x.good();       // OK
  auto &&g2 = x.operator*();  // OK
  auto &&error = *x;          // error here
}

void func2(int)
{
  A x;
  auto &&g = *x;              // OK
}

int main()
{
  func(0);
  func2(0);
}

gcc 4.6 and 4.7 can't compile the line marked "error here".  The error looks
like:

auto-rvalue.cc: In instantiation of ‘void func(T) [with T = int]’:
auto-rvalue.cc:24:9:   required from here
auto-rvalue.cc:13:19: error: invalid initialization of non-const reference of
type ‘int&’ from an rvalue of type ‘int’

I suppose this could be correct, but I'd be very surprised.  clang++ 2.9
accepts this code.

Reply via email to