Typo on msdn "C ++ Constant Expressions" page?

The msdn page talks about C ++ constant expressions that:

Non-integral constants must be converted (either explicitly or implicitly) to integral types, which must be legal in constant expression. Therefore, the following code is legal:

const double Size = 11.0; char chArray[(int)Size]; 

At least in VC ++ 10.0, the second line produces: "error C2057: expected constant expression". Is this legal with any other compiler, or is the msdn page just plain wrong?

+3
c ++ constant-expression msdn
source share
2 answers

According to 5.19 / 1:

An integral constant expression may include only literals (2.13), enumerations, const variables or static integral data elements or enumeration types initialized using constant expressions (8.5), non-type integral template parameters or enumeration types and sizeof expressions. Floating literals (2.13.3) can appear only if they are discarded on the integral or enumeration Types .

From my understanding, the code is invalid while legal:

 char chArray[(int)11.0]; 
+6
source share

This is illogical according to the C ++ standard. See 5.19 / 2 for rules in the specification.

+3
source share

All Articles