<html>
    <head>
      <base href="https://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 --- - diagnose assignment at top level in constant-expression better" href="https://urldefense.proofpoint.com/v2/url?u=https-3A__llvm.org_bugs_show-5Fbug.cgi-3Fid-3D24250&d=AwMBaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=pF93YEPyB-J_PERP4DUZOJDzFVX5ZQ57vQk33wu0vio&m=zyLzl1SqRei8nG93LQOMIgIa_m17E6D4SdwCCee_6O4&s=yNyyN5JtF2ux_q83wbCPGfQvTbyPw4Vocm08B2_sMTo&e=">24250</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>diagnose assignment at top level in constant-expression better
          </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>Linux
          </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++
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>richard-llvm@metafoo.co.uk
          </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>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).</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>