Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@StephanTLavavej
Copy link
Member

Found by std/localization/locales/locale/locale.cons/char_pointer.pass.cpp in the upcoming libcxx update:

D:\GitHub\STL\llvm-project\libcxx\test\std\localization\locales\locale\locale.cons\char_pointer.pass.cpp(92): error C2440: '<function-style-cast>': cannot convert from 'nullptr' to 'std::locale'
D:\GitHub\STL\llvm-project\libcxx\test\std\localization\locales\locale\locale.cons\char_pointer.pass.cpp(92): note: 'std::locale::locale': ambiguous call to overloaded function
D:\GitHub\STL\out\x64\out\inc\xlocale(304): note: could be 'std::locale::locale(const char *,std::locale::category)'
D:\GitHub\STL\out\x64\out\inc\xlocale(394): note: or       'std::locale::locale(std::locale::_Locimp *)'
D:\GitHub\STL\llvm-project\libcxx\test\std\localization\locales\locale\locale.cons\char_pointer.pass.cpp(92): note: while trying to match the argument list '(nullptr)'

WG21-N4964 [member.functions]/2:

For a non-virtual member function described in the C++ standard library, an implementation may declare a different set of member function signatures, provided that any call to the member function that would select an overload from the set of declarations described in this document behaves as if that overload were selected.

The set of constructors depicted in [locale.general] means that locale{nullptr} should compile, even though [locale.cons]/3 says that when it selects explicit locale(const char* std_name);:

Throws: runtime_error if the argument is not valid, or is null.

libc++'s test suite expects exactly this.

C++ is intentionally designed to perform access control after overload resolution (citation left as an exercise to the reader), so the private constructor locale(_Locimp*) disrupts this. We can add an internal tag to restore conformance. Because this is private, the tag can also be private.

Verified that there are no differences in release or debug exports (perhaps surprisingly, locale isn't separately compiled, although its unindicted co-conspirators are).

Verified that there are no differences in release or debug exports.

Found by std/localization/locales/locale/locale.cons/char_pointer.pass.cpp with:

D:\GitHub\STL\llvm-project\libcxx\test\std\localization\locales\locale\locale.cons\char_pointer.pass.cpp(92): error C2440: '<function-style-cast>': cannot convert from 'nullptr' to 'std::locale'
D:\GitHub\STL\llvm-project\libcxx\test\std\localization\locales\locale\locale.cons\char_pointer.pass.cpp(92): note: 'std::locale::locale': ambiguous call to overloaded function
D:\GitHub\STL\out\x64\out\inc\xlocale(304): note: could be 'std::locale::locale(const char *,std::locale::category)'
D:\GitHub\STL\out\x64\out\inc\xlocale(394): note: or       'std::locale::locale(std::locale::_Locimp *)'
D:\GitHub\STL\llvm-project\libcxx\test\std\localization\locales\locale\locale.cons\char_pointer.pass.cpp(92): note: while trying to match the argument list '(nullptr)'
@StephanTLavavej StephanTLavavej added the bug Something isn't working label Dec 6, 2023
@StephanTLavavej StephanTLavavej requested a review from a team as a code owner December 6, 2023 04:57
@CaseyCarter CaseyCarter removed their assignment Dec 6, 2023
@StephanTLavavej StephanTLavavej self-assigned this Dec 7, 2023
@StephanTLavavej
Copy link
Member Author

I'm mirroring this to the MSVC-internal repo - please notify me if any further changes are pushed.

@StephanTLavavej StephanTLavavej merged commit cf1313c into microsoft:main Dec 7, 2023
@StephanTLavavej StephanTLavavej deleted the locale-nullptr branch December 7, 2023 17:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants