我的错误,还是英特尔编译器中的错误? sizeof 非静态成员错误

My mistake, or bug in intel compiler? sizeof a non-static member error

我相信这段代码:

#include <stdio.h>

struct foo {
    char array[1024];
};

int main() { 
    fprintf(stderr, "sizeof(foo::array): %zd\n", sizeof(foo::array));    
}

是有效的 C++。 g++ 用 -ansi -pedantic 编译它就好了。但是,使用 Intel 的 icc 12.1.3 编译我得到:

error #288: a nonstatic member reference must be relative to a specific object

是我的错误还是 icc 做错了事:C++ 规范?

这是一个编译器错误,或者编译器可能是在标准采用此功能之前发布的。

根据 C++ 标准(5.1 基本表达式)

13 An id-expression that denotes a non-static data member or non-static member function of a class can only be used:

— if that id-expression denotes a non-static data member and it appears in an unevaluated operand.

[ Example:
struct S {
int m;
};
int i = sizeof(S::m); // OK
int j = sizeof(S::m + 42); // OK
—end example ]