If reordering member declarations in a class yields an alternate valid
program under (1) and (2), the program is ill-formed, no
diagnostic is required.
Despite the removal of this exact (superfluous) bullet point due to CWG issue #1875, note the bolded part; If we reorder the declarations
struct A
{
T i;
typedef char T;
};
The program is not conforming to rule 2):
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
. No
diagnostic is required for a violation of this rule.
T
is used in the declaration of i
, where it refers to the global typedef
. However, when reevaluated in the completed scope of A
, T
refers to the member typedef, which is clearly a different declaration.
This rule is not violated by your code, though.
The standard gives an example to show the difference between my first snippet and yours, and their validity. [basic.scope.class]/5:
typedef char* T;
struct Y {
T a; // error: T refers to ::T
// but when reevaluated is Y::T
typedef long T;
T b;
};
Thus the code in your question is indeed well-formed.