<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 --- - Struct size is 0 even if the compiler emites "warning: struct has size 0 in C, size 1 in C++ [-Wc++-compat]""
   href="https://llvm.org/bugs/show_bug.cgi?id=24711">24711</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Struct size is 0 even if the compiler emites "warning: struct has size 0 in C, size 1 in C++ [-Wc++-compat]"
          </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>douglas_yung@playstation.sony.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>dgregor@apple.com, llvm-bugs@lists.llvm.org
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Consider the following code:

/*** test.c ***/
#include <stdio.h>

struct S {
  char tmp[0];
};

struct T {
  struct S v01;
  struct S v02;
};

int main(void) {
  printf("%lu\n", sizeof(struct S));
  printf("%lu\n", sizeof(struct T));
  return 0;
}
/*****/

If you compile this as a .c file on x64 linux targeting x64 linux, using
-Wc++-compat, you get the following warnings:

test.c:3:1: warning: struct has size 0 in C, size 1 in C++ [-Wc++-compat]
struct S {
^
test.c:7:1: warning: struct has size 0 in C, non-zero size in C++
[-Wc++-compat]
struct T {
^

But if rename the file to be .cpp and recompile, you find that both of those
warnings are not true. The size of both S and T are reported to be 0, which
does at least seem to be consistent with what gcc produces.</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>