c++language-designc++03c++98

Why did C++03 allow data members with the same name as the class?


Between the C++98 standard and the C++03 standard, an interesting change was made:

struct S {
    int S;
};

This code is valid in C++03 and newer, but was ill-formed in C++98. Specifically, [class.mem] paragraph 13 banned all data members from having the same name as the class in C++98, but this rule was relaxed so that if there is no user-declared constructor, you can have a non-static data member with the same name.

What is the motivation behind this? What important use case is covered by this that would warrant revising the standard?


Solution

  • This is from DR80. To paraphrase, static was there originally to conform with C but between the May '96 and September '96 working papers the standard was changed and static was removed. C++03 reverted that error from the language via the defect report.