<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Tue, Jul 15, 2014 at 9:21 PM, Nikola Smiljanic <span dir="ltr"><<a href="mailto:popizdeh@gmail.com" target="_blank">popizdeh@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div>These are enabled as language extension and will produce an error if you pass -pedantic to clang. There might be another, more fine-grained, switch that controls these.</div>
<div><br></div><div>_Alignof(void(int)) produces: invalid application of alignof to a function type<br>

</div><div><div>_Alignof(void) produces: invalid application of alignof to a void type</div></div></div></blockquote><div><br></div><div>Function types and void have size 1 and alignment 1 as a GNU extension.</div><div><br>
</div><div>(Hmm, we really should add that -fno-gnu-extensions flag one day...)</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="HOEnZb"><div class="h5">
<div class="gmail_extra"><div class="gmail_quote">On Wed, Jul 16, 2014 at 2:05 PM, <a href="mailto:zhangxp@cn.fujitsu.com" target="_blank">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, Nikola!<br>
<br>
I known "_Alignof(struct S)" will cause error, and I mean why "_Alignof(void(int))" not cause clang to report error.<br>
<div><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>
</div>                           ^^^^^^^^^                 ^^^^^^^^^^^^^<br>
<br>
Sandy Zhang<br>
<br>
From: Nikola Smiljanic [mailto:<a href="mailto:popizdeh@gmail.com" target="_blank">popizdeh@gmail.com</a>]<br>
Sent: Wednesday, July 16, 2014 11:24 AM<br>
To: Zhang, Xiongpang/张 汹滂<br>
Cc: <a href="mailto:cfe-dev@cs.uiuc.edu" target="_blank">cfe-dev@cs.uiuc.edu</a><br>
Subject: Re: [cfe-dev] clang allow the _Alignof operator being applied to a function type?<br>
<div><div><br>
Clang trunk reports:<br>
<br>
test.c:3:13: error: invalid application of 'alignof' to an incomplete type 'struct S'<br>
    int b = _Alignof(struct S);<br>
               ^           ~~~~~~<br>
test.c:3:29: note: forward declaration of 'struct S'<br>
    int b = _Alignof(struct S);<br>
                                     ^<br>
<br>
On Wed, Jul 16, 2014 at 12:06 PM, <a href="mailto:zhangxp@cn.fujitsu.com" target="_blank">zhangxp@cn.fujitsu.com</a> <<a href="mailto:zhangxp@cn.fujitsu.com" target="_blank">zhangxp@cn.fujitsu.com</a>> wrote:<br>
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" target="_blank">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>
<br>
</div></div></blockquote></div><br></div>
</div></div><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>
<br></blockquote></div><br></div></div>