[LLVMbugs] [Bug 19592] New: really bad diagnostic on array conversion operator

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Mon Apr 28 16:20:57 PDT 2014


http://llvm.org/bugs/show_bug.cgi?id=19592

            Bug ID: 19592
           Summary: really bad diagnostic on array conversion operator
           Product: clang
           Version: trunk
          Hardware: PC
                OS: All
            Status: NEW
          Severity: normal
          Priority: P
         Component: C++11
          Assignee: unassignedclangbugs at nondot.org
          Reporter: nlewycky at google.com
                CC: dgregor at apple.com, llvmbugs at cs.uiuc.edu
    Classification: Unclassified

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 ..."?

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20140428/aa626dee/attachment.html>


More information about the llvm-bugs mailing list