以下代码可以用 clang 编译。我想知道 C++ 标准是否适合这个。
class A {
static void x; // #1
static const void x; // #2
static volatile void x; // #3
};
在我看来,所有的声明都是无效的。 perenial C++ standard validation suite 有这样一个这样的测试 (#1) 和 clang (v3.4) 失败了。
不过,如果我从 #1 中删除静态,则 clang 会按预期报告错误。
我查看了标准,发现了一段关于静态数据成员 (9.4.2-2) 的内容:
2 The declaration of a static data member in its class definition is not a definition and may be of an incomplete type other than cv-qualified void. ...
据我了解,此行将 #2 和 #3 视为无效但不确定 #1。是否有更多与静态存储类声明相关的细节应该排除#1?
谢谢,
最佳答案
不,这是不允许的,正是因为您引用的段落。请注意,您引用的段落中的术语“cv-qualified”包括不合格。根据 C++11 标准的第 3.9.3/10 段:
In this International Standard, the notation
cv
(orcv1
,cv2
, etc.), used in the description of types, represents an arbitrary set of cv-qualifiers, i.e., one of {const
}, {volatile
}, {const
,volatile
}, or the empty set.
关于c++ - 'static void' 作为 decl-specifier,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17432891/