-
Notifications
You must be signed in to change notification settings - Fork 15.1k
Description
Due to the presence of non-uglified member typedef-names in std::bitset, the following program fails to compile in libc++ (while it compiles successfully in libstdc++ and MSVC):
https://godbolt.org/z/4EGY13eah
#include <bitset>
struct MyBase {
using const_reference = const int&;
using size_type = unsigned;
using difference_type = int;
};
struct MyDerived : MyBase, std::bitset<42> {};
int main() {
MyDerived::const_reference r{};
MyDerived::size_type s{};
MyDerived::difference_type d{};
}Affected Lines:
llvm-project/libcxx/include/bitset
Lines 170 to 174 in e3dafa8
| template <size_t _N_words, size_t _Size> | |
| class __bitset { | |
| public: | |
| typedef ptrdiff_t difference_type; | |
| typedef size_t size_type; |
llvm-project/libcxx/include/bitset
Lines 433 to 436 in e3dafa8
| class __bitset<1, _Size> { | |
| public: | |
| typedef ptrdiff_t difference_type; | |
| typedef size_t size_type; |
llvm-project/libcxx/include/bitset
Lines 550 to 553 in e3dafa8
| class __bitset<0, 0> { | |
| public: | |
| typedef ptrdiff_t difference_type; | |
| typedef size_t size_type; |
llvm-project/libcxx/include/bitset
Line 622 in e3dafa8
| typedef typename __base::const_reference const_reference; |
Proposed Solution:
In my opinion, if the standard does not specify a member typedef, the library should try to avoid or minimize the introduction of extra typedefs, especially public ones, to prevent potential clashes with user-defined classes, as demonstrated above. From the user's perspective, they have the freedom to utilize any member typedefs not specified by the C++ standards in their own code.
If extra typedefs are deemed necessary, I recommend using a naming convention like __ugly_name for those not specified in the standards, as we have previously implemented.