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

zhangxp at cn.fujitsu.com zhangxp at cn.fujitsu.com
Tue Jul 15 21:05:37 PDT 2014


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





More information about the cfe-dev mailing list