[llvm-bugs] [Bug 24711] New: Struct size is 0 even if the compiler emites "warning: struct has size 0 in C, size 1 in C++ [-Wc++-compat]"
via llvm-bugs
llvm-bugs at lists.llvm.org
Fri Sep 4 13:15:46 PDT 2015
https://llvm.org/bugs/show_bug.cgi?id=24711
Bug ID: 24711
Summary: Struct size is 0 even if the compiler emites "warning:
struct has size 0 in C, size 1 in C++ [-Wc++-compat]"
Product: clang
Version: trunk
Hardware: PC
OS: Linux
Status: NEW
Severity: normal
Priority: P
Component: C++
Assignee: unassignedclangbugs at nondot.org
Reporter: douglas_yung at playstation.sony.com
CC: dgregor at apple.com, llvm-bugs at lists.llvm.org
Classification: Unclassified
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.
--
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20150904/37667cbd/attachment.html>
More information about the llvm-bugs
mailing list