-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Description
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 templatechar_traits:char_traits<char>,char_traits<char8_t>,char_traits<char16_t>,char_traits<char32_t>, andchar_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':
STL/stl/inc/__msvc_string_view.hpp
Lines 678 to 680 in c7c5ca7
| 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."); |