Skip to content

[libc++] std::bitset has non-uglified member typedefs size_type, difference_type, and const_reference causing ambiguity in name lookup #121618

@winner245

Description

@winner245

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:

template <size_t _N_words, size_t _Size>
class __bitset {
public:
typedef ptrdiff_t difference_type;
typedef size_t size_type;

class __bitset<1, _Size> {
public:
typedef ptrdiff_t difference_type;
typedef size_t size_type;

class __bitset<0, 0> {
public:
typedef ptrdiff_t difference_type;
typedef size_t size_type;

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.

Metadata

Metadata

Assignees

Labels

libc++libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions