<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 - accept-invalid: __builtin_types_compatible_p pollutes the environment of tag type checking"
   href="https://bugs.llvm.org/show_bug.cgi?id=49337">49337</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>accept-invalid: __builtin_types_compatible_p pollutes the environment of tag type checking
          </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>-New Bugs
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>zhan3299@purdue.edu
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>htmldeveloper@gmail.com, llvm-bugs@lists.llvm.org, neeilans@live.com, richard-llvm@metafoo.co.uk
          </td>
        </tr></table>
      <p>
        <div>
        <pre>I am not sure how to accurately describe the problem. In short,

Following code is obviously invalid, as the use of 'X' with tag type does not
match previous declaration (<a href="https://godbolt.org/z/qad8vz">https://godbolt.org/z/qad8vz</a>).

$ cat case1.c
struct X {
    union X {
        int b;
        long c;
    } d;
} a;

int main() { return 0; }


However, when we put this erroneous declaration into a
__builtin_types_compatible_p function, clang accepts it
(<a href="https://godbolt.org/z/TrxTzs">https://godbolt.org/z/TrxTzs</a>). Note that it is rejected by GCC
(<a href="https://godbolt.org/z/rWde88">https://godbolt.org/z/rWde88</a>).

$ cat case2.c
int main() {
    int a = __builtin_types_compatible_p(int, struct X {
        union X {
            int b;
            long c;
        } d;
    });

    return a;
}


Even worse, this invalid __builtin_types_compatible_p may additionally affects
other statements (<a href="https://godbolt.org/z/avxvzj">https://godbolt.org/z/avxvzj</a>), which, at least, gives the
wrong error reports.

$ cat case3.c
int main() {
    int a = __builtin_types_compatible_p(int, struct X {
        union X {
            int b;
            long c;
        } d;
    });

    enum X { A, B } h;
    h = A;

    return a;
}

$ clang case3.c

#1 with x86-64 clang (trunk)
case3.c:10:9: error: use of undeclared identifier 'A'
    h = A;
        ^
1 error generated.</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>