Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

'static void' as decl-specifier

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,

like image 417
A. K. Avatar asked Jul 02 '13 18:07

A. K.


1 Answers

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 (or cv1, 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.

like image 175
Andy Prowl Avatar answered Nov 09 '22 08:11

Andy Prowl