-
-
Notifications
You must be signed in to change notification settings - Fork 6.8k
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
Is it possible to have template json::parse
with noexcept
specifier?
#1922
Comments
Somehow this was not inserted into issue text, I'll paste it here. json/single_include/nlohmann/json.hpp Lines 20744 to 20747 in 6a6790a
|
I've found a macro that may affect exception policy of the library. json/single_include/nlohmann/json.hpp Lines 1747 to 1758 in 6a6790a
Example: #if (defined(__cpp_exceptions) || defined(__EXCEPTIONS) || defined(_CPPUNWIND)) && !defined(JSON_NOEXCEPTION)
/* ... */
#define JSON_NOEXCEPT noexcept(false)
#else
/* ... */
#define JSON_NOEXCEPT noexcept
#endif
/* ... */
JSON_HEDLEY_WARN_UNUSED_RESULT
static basic_json parse(detail::input_adapter&& i,
const parser_callback_t cb = nullptr,
const bool allow_exceptions = true)
JSON_NOEXCEPT
{
/* ... */
}
/* ... */
// clean up
/* ... */
#undef JSON_NOEXCEPT |
Technically, the parse function is not noexcept, because it allocates memory which can yield |
Got it, so no more questions :) |
Describe what you want to achieve.
Have
noexcept
forjson::parse
methods if the third argument isfalse
.Describe what you tried.
I've tried to use this method in my exception-free code, but my IDE (especially ReSharper C++ plugin) warned me about unhandled exceptions from calling this function. Also
noexcept
specifier makes optimization passes to be more aggressive.Describe which system (OS, compiler) you are using.
Microsoft Windows 10, MSVC (from Microsoft Visual Studio 2017), CMake (from 3.12), Vcpkg (version
2020.01.17-nohash
).Describe which version of the library you are using (release version, develop branch).
Version available as the last in
vcpkg
(in library source marked as 3.7.3).The text was updated successfully, but these errors were encountered: