-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
P2166R1 Prohibiting basic_string And basic_string_view Construction From nullptr #1995
P2166R1 Prohibiting basic_string And basic_string_view Construction From nullptr #1995
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One question regarding consistency.
Also while you are in the vicinity, would you be interested in #1977 |
Yeah I'm interested to tackle that too if that's available. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also: I added an entry to the yvals_core.h
list of implemented proposals in a new _HAS_CXX23 directly controls:
section. (It seemed easier to just push a commit than to try to explain the proper place since we don't have a _HAS_CXX23
section yet.)
Is this supposed to be applied retroactively, or to C++23 only? cplusplus/papers#887 is tagged "C++20". |
This PR needs to merge |
GitHub's merge conflict editor doesn't like this repo's line endings.
IMO it should go all the way back to C++11. The fact that this compiles is super dumb, #include <string>
std::string boom()
{
return 0;
} |
…com/sam20908/STL into cxx23_prohibit_nullptr_construction
This reverts commit 20f233b.
Merge finally fixed... |
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great! I'll validate and push trivial changes to the test.
Good question. Looking at that issue's history, it appears that it was tagged C++20 because it was considered for retroactive application - however, it appears that they decided against that. The final motion that was sent to the plenary vote was for C++23 only.
I agree that this detects totally bad code, although I'd be slightly concerned about customers complaining that this causes compiler errors for code that isn't executed at runtime. It does seem almost like |
Thanks for implementing this C++23 feature which has already found incorrect code in the compiler! 😹 |
This comment has been minimized.
This comment has been minimized.
No, adding the C++20 label there appears to just be an admin error in the paper tracker. This paper was never in scope for C++20 and never intended to be a DR against C++20.
That's what I did for GCC.
I got a number of reports like that, but everybody agreed to fix their bad code. Nobody argued "it's OK, we never actually run this undefined code, we want to keep it!" The real problem with making it apply back to C++11 is it changes previously-correct code to ill-formed: #include <string>
struct S
{
operator const char*() const { return ""; }
operator std::nullptr_t() const { return {}; }
};
std::string s{ S{} }; This is valid in C++20 and earlier, but ill-formed in C++23. GCC rejects this in C++20, which I suppose is a bug. |
It's hard for me not to see a type that converts to both |
No argument here. I think the json issue was actually something more like this, where there's a variant-like type that can be implicitly converted to various types: struct J
{
// In C++20 this selects basic_string(const char*),
// in C++23 it's ambiguous due to basic_string(nullptr_t).
template<typename T>
requires (!std::is_same_v<std::allocator<char>, T>)
&& (!std::is_same_v<std::string, T>)
&& (!std::is_same_v<char, T>)
&& (!std::is_same_v<std::string_view, T>)
operator T() const { return {}; }
};
std::string s3{ J{} }; And this seems extremely fragile too. |
Fixes #1979