<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </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 - Clang accepts invalid code"
   href="https://bugs.llvm.org/show_bug.cgi?id=42212">42212</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Clang accepts invalid code
          </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>enhancement
          </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>zhonghao@pku.org.cn
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>blitzrakete@gmail.com, dgregor@apple.com, erik.pilkington@gmail.com, llvm-bugs@lists.llvm.org, richard-llvm@metafoo.co.uk
          </td>
        </tr></table>
      <p>
        <div>
        <pre>My clang is 9.0.0, and the code is:

void f() {
 union {
 typeof
 (
 (
 {
 unsigned long __ptr;
 (int *)(0);
 }
 )
 )
 __val;
 };
}


clang accepts the code, but icc, gcc and msvc all reject it.

msvc:

<source>(5): error C2059: syntax error: '('

<source>(6): error C2143: syntax error: missing ')' before '{'

<source>(6): error C4430: missing type specifier - int assumed. Note: C++ does
not support default-int

<source>(9): warning C4183: 'typeof': missing return type; assumed to be a
member function returning 'int'

<source>(10): error C2059: syntax error: ')'

<source>(11): error C2059: syntax error: ')'

<source>(12): error C2238: unexpected token(s) preceding ';'

<source>(13): error C2627: 'typeof': member function not allowed in anonymous
union

Compiler returned: 2

icc:

<source>(7): internal error: bad pointer

   unsigned long __ptr;

   ^

compilation aborted for <source> (code 4)

Compiler returned: 4

gcc:

    x86-64 gcc (trunk) (Editor #1, Compiler #1) C++

x86-64 gcc (trunk)
1
<Compilation failed>
No Results
x86-64 gcc (trunk)
- cached

    #1 with x86-64 gcc (trunk)

<source>: In function 'void f()':

<source>:5:2: error: statement-expressions are not allowed outside functions
nor in template-argument lists

    5 |  (

      |  ^

Compiler returned: 1</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>