[cfe-dev] clang allow the _Alignof operator being applied to a function type?

Richard Smith richard at metafoo.co.uk
Tue Jul 15 21:34:48 PDT 2014


On Tue, Jul 15, 2014 at 9:21 PM, Nikola Smiljanic <popizdeh at gmail.com>
wrote:

> 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.
>
> _Alignof(void(int)) produces: invalid application of alignof to a function
> type
> _Alignof(void) produces: invalid application of alignof to a void type
>

Function types and void have size 1 and alignment 1 as a GNU extension.

(Hmm, we really should add that -fno-gnu-extensions flag one day...)


> On Wed, Jul 16, 2014 at 2:05 PM, zhangxp at cn.fujitsu.com <
> zhangxp at cn.fujitsu.com> wrote:
>
>> Hi, Nikola!
>>
>> I known "_Alignof(struct S)" will cause error, and I mean why
>> "_Alignof(void(int))" not cause clang to report error.
>>
>> C11 6.5.3.4/p1 says:
>>     "The _Alignof operator shall not be applied to a function type or an
>> incomplete type."
>>                            ^^^^^^^^^                 ^^^^^^^^^^^^^
>>
>> Sandy Zhang
>>
>> From: Nikola Smiljanic [mailto:popizdeh at gmail.com]
>> Sent: Wednesday, July 16, 2014 11:24 AM
>> To: Zhang, Xiongpang/张 汹滂
>> Cc: cfe-dev at cs.uiuc.edu
>> Subject: Re: [cfe-dev] clang allow the _Alignof operator being applied to
>> a function type?
>>
>> Clang trunk reports:
>>
>> test.c:3:13: error: invalid application of 'alignof' to an incomplete
>> type 'struct S'
>>     int b = _Alignof(struct S);
>>                ^           ~~~~~~
>> test.c:3:29: note: forward declaration of 'struct S'
>>     int b = _Alignof(struct S);
>>                                      ^
>>
>> On Wed, Jul 16, 2014 at 12:06 PM, zhangxp at cn.fujitsu.com <
>> zhangxp at cn.fujitsu.com> wrote:
>> Hi, all!
>>
>> C11 6.5.3.4/p1 says:
>>     "The _Alignof operator shall not be applied to a function type or an
>> incomplete type."
>>
>> But I compiled the following code with clang-3.4 and gcc-4.9 on linux
>> (x86_64):
>> ----------------------------------------------
>> extern int printf(const char* fmt, ...);
>> int main() {
>>     int a = _Alignof(void(int));
>>     int b = _Alignof(void);
>>     // int c = _Alignof(struct S); // error: invalid application of
>> 'alignof' to an incomplete type 'struct S'
>>     printf("a == %d, b == %d\n", a, b);
>> }
>> ----------------------------------------------
>> Results:
>>     clang-3.4: a == 4, b == 1
>>     gcc-4.9  : a == 1, b == 1
>>
>> Question:
>>     Why both clang and gcc not report error like "invalid application of
>> 'alignof' to a function/incomplete type 'xxxx'"?
>>
>> Sandy Zhang
>>
>>
>> _______________________________________________
>> cfe-dev mailing list
>> cfe-dev at cs.uiuc.edu
>> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
>>
>>
>
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20140715/ef45ea65/attachment.html>


More information about the cfe-dev mailing list