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

Nikola Smiljanic popizdeh at gmail.com
Tue Jul 15 20:24:20 PDT 2014


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
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20140716/56b67a12/attachment.html>


More information about the cfe-dev mailing list