Is it portable to have a subtle semicolon in the class declaration

class Test
{
  ;
  int x;
};

      

Is it perfectly legal and portable?

+3


source to share


1 answer


From my reading of the standard, this is not allowed.

If you only look at the definition of grammar it seems to allow. Relevant parts:

a BOM member is what appears in between { ... }

in a class declaration.

member-specification is a sequence of member declarations and access specifiers. One possible form for a member-declaration :

attribute-spec-fi-seq opt decl-speci-er-seq opt member-declarator- list opt;



Since everything up to the semicolon is optional, it looks like it is allowed to have an empty   member-declaration consisting of only semicolons.

However, 9.2 / 1 says:

Unless used to declare friends (11.3) or to represent the name of a base class member in a derived class (7.3.3), member declarations declare class members, and each such -declaration declares at least one class member name .

Since an empty member declaration does not declare at least one class member, it seems that this is not standard-compliant, even though some compilers accept it.

+6


source







All Articles