In the following example, will the size of array v guaranteed to be 2 or 3?
static const int i = 3;
class X {
char v[i];
static const int i = 2;
};
From the standard,
3.3.6/2 A name N used in a class S shall refer to the same declaration in its context and when re-evaluated in the completed scope of S
I think this means ‘i’ shall be 2 and what does the re-evaluation thing really means here?
The correct behavior is that it should cause an error because re-evaluation would change the meaning:
Example from section 3.3.6:
The example is similar to yours (using
enuminstead of astatic const int):At the time
v[i]is encountered, the compiler only knows aboutenum { i = 1 };(orstatic const int i = 3;, but when the full class declaration is known,char v[i]would be different becauseiwould be re-evaluated to2.