https://llvm.org/bugs/show_bug.cgi?id=24250

            Bug ID: 24250
           Summary: diagnose assignment at top level in
                    constant-expression better
           Product: clang
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: C++
          Assignee: [email protected]
          Reporter: [email protected]
                CC: [email protected], [email protected]
    Classification: Unclassified

Top-level assignment in a constant-expression is forbidden by the grammar (and
thus rejected in Clang's parser). This results in some confusing diagnostics:

struct N { constexpr int operator=(int n) { return n; } } n;
int a[n = 0];
template<int> struct X {};
X<n = 0> x;
enum E { e = n = 0 };                                                 
struct Q { int k : n = 0; };

Gives:

<stdin>:2:9: error: expected ']'
int a[n = 0];
        ^
<stdin>:2:6: note: to match this '['
int a[n = 0];
     ^
<stdin>:2:7: error: size of array has non-integer type 'struct N'
int a[n = 0];
      ^
<stdin>:4:5: error: expected '>'
X<n = 0> x;
    ^
<stdin>:4:5: error: expected unqualified-id
<stdin>:5:14: error: integral constant expression must have integral or
unscoped enumeration type, not 'struct N'
enum E { e = n = 0 };
             ^
<stdin>:5:16: error: expected '}' or ','
enum E { e = n = 0 };
               ^
<stdin>:6:22: error: bitfield member cannot have an in-class initializer
struct Q { int k : n = 0; };
                     ^
<stdin>:6:20: error: integral constant expression must have integral or
unscoped enumeration type, not 'struct N'
struct Q { int k : n = 0; };
                   ^

It would be nice to diagnose these cases better (except for the last case,
where the current diagnostic seems appropriate).

-- 
You are receiving this mail because:
You are on the CC list for the bug.
_______________________________________________
LLVMbugs mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/llvmbugs

Reply via email to