<div dir="ltr">Clang trunk reports:<div><br></div><div><div>test.c:3:13: error: invalid application of 'alignof' to an incomplete type 'struct S'</div><div> int b = _Alignof(struct S);</div><div> ^ ~~~~~~</div>
<div>test.c:3:29: note: forward declaration of 'struct S'</div><div> int b = _Alignof(struct S);</div><div> ^</div></div></div><div class="gmail_extra"><br><br><div class="gmail_quote">
On Wed, Jul 16, 2014 at 12:06 PM, <a href="mailto:zhangxp@cn.fujitsu.com">zhangxp@cn.fujitsu.com</a> <span dir="ltr"><<a href="mailto:zhangxp@cn.fujitsu.com" target="_blank">zhangxp@cn.fujitsu.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi, all!<br>
<br>
C11 <a href="http://6.5.3.4/p1" target="_blank">6.5.3.4/p1</a> says:<br>
"The _Alignof operator shall not be applied to a function type or an incomplete type."<br>
<br>
But I compiled the following code with clang-3.4 and gcc-4.9 on linux (x86_64):<br>
----------------------------------------------<br>
extern int printf(const char* fmt, ...);<br>
int main() {<br>
int a = _Alignof(void(int));<br>
int b = _Alignof(void);<br>
// int c = _Alignof(struct S); // error: invalid application of 'alignof' to an incomplete type 'struct S'<br>
printf("a == %d, b == %d\n", a, b);<br>
}<br>
----------------------------------------------<br>
Results:<br>
clang-3.4: a == 4, b == 1<br>
gcc-4.9 : a == 1, b == 1<br>
<br>
Question:<br>
Why both clang and gcc not report error like "invalid application of 'alignof' to a function/incomplete type 'xxxx'"?<br>
<br>
Sandy Zhang<br>
<br>
<br>
_______________________________________________<br>
cfe-dev mailing list<br>
<a href="mailto:cfe-dev@cs.uiuc.edu">cfe-dev@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev</a><br>
</blockquote></div><br></div>