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

            Bug ID: 68891
           Summary: must use a typedef to declare a conversion to 'double
                    (&)[3]'
           Product: gcc
           Version: 5.2.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: mathieu.malaterre at gmail dot com
  Target Milestone: ---

Per my understanding of C++ standard section ยง12.3.2, the following piece of
code should not compile:

$ cat c.cxx
#include <iostream>
struct V
{
  (&operator double ())[3] {
    return v;
  }
  double v[3];
};

static void Print( const double (&a)[3] )
{
  std::cout << a[0] << "," << a[1] << "," << a[2] << std::endl;
}

int main()
{
  V v = {0,1,2};
  Print( v );
  return 0;
}

Seems to be valid c++ for gcc 5.2.1:

$ g++ -Wall -W -pedantic c.cxx && ./a.out 
0,1,2

The only accepted syntax should be using a `typedef` keyword:

  typedef double (&array_ref)[3];
  operator array_ref () { return v; }

Reply via email to