Following code compiles fine with clang. I wanted to know if the C++ standard is okay with this.
class A {
static void x; // #1
static const void x; // #2
static volatile void x; // #3
};
In my opinion none of the declarations are valid. The perenial C++ standard validation suite has such one such test (#1) and clang (v3.4) fails in that.
Although, if I remove static from #1 then clang reports error as expected.
I looked at the standard and I found one paragraph on static data members (9.4.2-2) which says:
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. ...
As I understand this line disqualifies #2 and #3 as invalid but not sure about #1. Are there any more details related to declaration with static storage class that should rule out #1?
Thanks,
No, this is not allowed, precisely because of the paragraph you quote. Notice, that the term "cv-qualified" in the paragraph you quote includes non-qualification. Per paragraph 3.9.3/10 of the C++11 Standard:
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With