-
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
<exception>: constructor does not copy what_arg if _HAS_EXCEPTIONS=0 #2114
Comments
Finally, @CaseyCarter reminded me that this constructor itself is non-Standard (this applies to the normal |
Thanks for the quick response! About the non-standard issue: I think it's not about the constructor of |
Ah, I see - thanks for the clarification. It hadn't occurred to me the the standard constructors in the derived classes are implemented in terms of this non-standard constructor in |
We talked about this at the weekly maintainer meeting and we believe that in the |
Describe the bug
When
_HAS_EXCEPTIONS
is defined to0
, the constructors of the exception classes do not copy thewhat_arg
, but only store the pointer:STL/stl/inc/exception
Line 90 in 4721611
This leads to errors if the pointee is a temporary string.
If
_HAS_EXCEPTIONS
is set to1
, a copy is made just as the standard would require it.Command-line test case
The following code outputs
[json.exception.parse_error] foo
if_HAS_EXCEPTIONS
is set to1
, and some garbage if_HAS_EXCEPTIONS
is set to0
:The example comes from https://github.com/nlohmann/json where exceptions are created by a SAX parser, but it is up to the client whether they are thrown or not. Therefore, using exception classes while disabling throwing exceptions is a usecase.
Expected behavior
The exception makes a copy of the
what_arg
argument, regardless of the value of_HAS_EXCEPTIONS
.STL version
I could reproduce the issue with MSVC 19.16.27045.0 and MSVC 19.29.30040.0.
Additional context
The issue was originally found here: nlohmann/json#2824
The text was updated successfully, but these errors were encountered: