<html>
    <head>
      <base href="http://llvm.org/bugs/" />
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW --- - really bad diagnostic on array conversion operator"
   href="http://llvm.org/bugs/show_bug.cgi?id=19592">19592</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>really bad diagnostic on array conversion operator
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>clang
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>trunk
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>All
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>normal
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>C++11
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedclangbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>nlewycky@google.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>dgregor@apple.com, llvmbugs@cs.uiuc.edu
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Testcase:

template <typename T, int N>
struct static_array {
 T contents[N];
 constexpr operator T[N]() { return contents; }
};

constexpr static_array<char, 10> foo() {
 static_array<char, 10> a = {0};
 for (int i = 0; i < 10; ++i)
   a.contents[i] = i;
 return a;
}

constexpr static_array<char, 10> sdf = foo();

Errors:

a.cc:4:2: error: non-static data member cannot be constexpr; did you intend to
make it static?
 constexpr operator T[N]() { return contents; }
 ^
 static 
a.cc:4:22: error: 'type name' declared as array of functions of type 'T ()'
 constexpr operator T[N]() { return contents; }
                     ^
a.cc:4:12: error: 'operator type-parameter-0-0' cannot be the name of a
variable or data member
 constexpr operator T[N]() { return contents; }
           ^
a.cc:4:30: error: expected expression
 constexpr operator T[N]() { return contents; }
                             ^
a.cc:7:34: warning: 'constexpr' non-static member function will not be
implicitly 'const' in C++1y; add 'const' to avoid a change in behavior
      [-Wconstexpr-not-const]
constexpr static_array<char, 10> foo() {
                                 ^
                                       const
a.cc:14:1: error: non-static data member cannot be constexpr; did you intend to
make it static?
constexpr static_array<char, 10> sdf = foo();
^
static 
a.cc:14:34: error: constexpr variable cannot have non-literal type 'const
static_array<char, 10>'
constexpr static_array<char, 10> sdf = foo();
                                 ^
a.cc:14:34: error: implicit instantiation of template 'static_array<char, 10>'
within its own definition
a.cc:14:40: error: call to non-static member function without an object
argument
constexpr static_array<char, 10> sdf = foo();
                                       ^~~
a.cc:15:1: error: expected '}'
^
a.cc:2:21: note: to match this '{'
struct static_array {
                    ^
a.cc:14:46: error: expected ';' after struct
constexpr static_array<char, 10> sdf = foo();
                                             ^
                                             ;
1 warning and 10 errors generated.


The fundamental problem is that "operator T[N]() { return foo; }" is an invalid
decl of a function returning T[N], but was (correctly) parsed as an array of
functions. The error for "expected expression" pointing at 'return' indicates
that it's reading the function body as if it were expecting an initializing
expression. It then manages to miss the closing brace causing the rest of the
spurious errors.

The occurrence of "type-parameter-0-0" is unfortunate. All template arguments
have names.

The occurrence of "'type name' declared ..." is also strange. Did it mean to
say "'conversion operator declared ..."?</pre>
        </div>
      </p>
      <hr>
      <span>You are receiving this mail because:</span>
      
      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>