-
Notifications
You must be signed in to change notification settings - Fork 2k
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
C++23 prohibits constructing std::string
from nullptr
#8265
Comments
Constructing strings from |
Note that std::string() was tried but somehow caused another bug (tape preset as play was instead stopped).
This bug was created almost 5 years ago and survived a number of refactors since. I tested See 645aef0 |
No further comments, so closing. Anyone who has a continuing interest in similar bugs may reopen this issue if they so wish. |
I work on MSVC's C++ Standard Library implementation, and we regularly build MAME (along with many other open-source projects) to identify compiler/library bugs that would break your project, so we can fix them before shipping. This also allows us to provide advance notice of source-breaking changes - which is the case here.
The paper P2166R1 "Prohibiting
basic_string
Andbasic_string_view
Construction Fromnullptr
" has been accepted for the upcoming C++23 Standard, and we recently implemented it by merging microsoft/STL#1995 from our contributor @sam20908. Our open-source test pass then discovered the following code in MAME that is now disallowed by C++23:mame/src/lib/formats/cassimg.cpp
Lines 224 to 230 in b0bc45a
Here,
cassette_image::open()
is passingnullptr
for theconst std::string &extension
parameter ofcassette_image::open_choices()
. This has always been undefined behavior in C++98 through C++20 (basic_string
's constructor has a precondition that the pointer is non-null); C++23 has added a deleted overload ofbasic_string
's constructor to detect when the argument is known to benullptr
at compile-time. (Runtime values ofconst char *
that happen to be null are still undefined behavior.)There are several possible ways to fix this code; you could pass an empty string with
""
orstd::string{}
or even{}
(depending on whetheropen_choices()
is overloaded).There may be additional occurrences of this throughout MAME's codebase - this is simply the first one we encountered. Hope this helps!
The text was updated successfully, but these errors were encountered: