Skip to content

<string>: basic_string<unsigned long long> is accepted #4935

@AlexGuteniev

Description

@AlexGuteniev

Describe the bug

Unsigned integral types are currently accepted as basic_string first template parameter with the second template parameter being default.

It should not compile, as there shouldn't be a specialization of std::char_traits for other types than standard character types.

[char.traits.specializations.general]/1:

The header <string> defines five specializations of the class template char_traits: char_traits<​char>, char_traits<char8_t>, char_traits<char16_t>, char_traits<char32_t>, and char_traits<wchar_t>.

Command-line test case

C:\Users\ALEXG~1\AppData\Local\Temp>type repro.cpp
#include <string>

int main() {
    std::basic_string<unsigned long long> s({1, 2, 3, 4});
}
C:\Users\ALEXG~1\AppData\Local\Temp>cl repro.cpp
Microsoft (R) C/C++ Optimizing Compiler Version 19.42.34226.3 for x64
Copyright (C) Microsoft Corporation.  All rights reserved.

repro.cpp
Microsoft (R) Incremental Linker Version 14.42.34226.3
Copyright (C) Microsoft Corporation.  All rights reserved.

/out:repro.exe
repro.obj

C:\Users\ALEXG~1\AppData\Local\Temp>repro.exe

C:\Users\ALEXG~1\AppData\Local\Temp>

Expected behavior

Should not compile

STL version

Version 17.12.0 Preview 1.0

Additional context

std::basic_string<unsigned long long, user_defined_traits> should still be valid.

Specializing std::char_traits for unsigned long long should not be supported (no diagnostics required I think).

A whole _String_bitmap specialization exists to support unsigned integral types; this support is mentioned as an 'extension':

static_assert(is_unsigned_v<_Elem>,
"Standard char_traits is only provided for char, wchar_t, char16_t, and char32_t. See N4950 [char.traits]. "
"Visual C++ accepts other unsigned integral types as an extension.");

Metadata

Metadata

Assignees

No one assigned

    Labels

    wontfixThis will not be worked on

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions