Which part of the C++ standard allow to declare variable in parenthesis?

Consider the following code:

int main() {
    int(s);
}

I am surprised by the fact that it creates valid variable s. Can anyone explain what's happening here?


[dcl.meaning] in the Standard says:

In a declaration T D where D has the form ( D1 ) the type of the contained declarator-id is the same as that of the contained declarator-id in the declaration T D1.

Parentheses do not alter the type of the embedded declarator-id, but they can alter the binding of complex declarators.

More simply, you can put parentheses around anything considered a "declarator" in the C++ grammar. (Loosely speaking, a declarator is a part of a declaration without the initial specifiers and types which contains one name.)

In your example, the identifier s is a declarator, so you're allowed to put parentheses around it and the meaning doesn't change.

The reason for this, as the second quoted sentence hints, is that it can be necessary when things get more complicated. One example:

int * a [10];     // a is an array of ten pointers to int.
int ( * b ) [10]; // b is a pointer to an array of ten ints.

Just to add to the other answers; in the grammar summary for declarators (C++14 [dcl.decl]/4) you can find:

ptr-declarator:
    noptr-declarator

noptr-declarator:
    ( ptr-declarator )

(I have omitted other details of the grammar). You can see from this that any declarator may be parenthesized and it would still match the same grammar rule.