-
-
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
[Clang] warning: use of the 'nodiscard' attribute is a C++17 extension [-Wc++17-extensions] #1535
Comments
The library checks whether the A solution could be to make the check more restrictive and switch off |
Me neither.
At the moment, I'm leaning towards this second option, but I'm eager to hear what others think. As a note, using: #pragma clang diagnostic ignored "-Wc++1z-extensions" Will cover earlier Clang versions that only support |
The downside of the first option seems more acceptable to me in the long run. If the first option is taken, the clang users with If the second option is taken, the developers of this library cannot enjoy warnings from #if __has_cpp_attribute(nodiscard)
#if defined(__clang__) && !defined(JSON_HAS_CPP_17) // issue #1535
#define JSON_NODISCARD
#else
#define JSON_NODISCARD [[nodiscard]]
#endif |
- Switch off `nodiscard` for clang unless C++17 is detected. - Detect C++ standard before the switch.
Remove C++17 extension warning from clang; #1535
🔖 release item in #1551. |
google/googletest@5a37b517ad introduced a check on `__has_cpp_attribute(maybe_unused)`. Under Clang this is true even in `-std=c++14` mode, but subsequently the use of the `[[maybe_unused]]` attribute triggers a `-Wc++17-extensions` warning (which we elevate to an error via `-pedantic-errors`). This is observed in the macOS Travis CI environment, where we use Apple Clang: https://app.travis-ci.com/github/tanzislam/cryptopals/jobs/625697125 A similar Clang issue with a different C++17 attribute was also observed in nlohmann/json#1535.
google/googletest@5a37b517ad introduced a check on `__has_cpp_attribute(maybe_unused)`. Under Clang this is true even in `-std=c++14` mode, but subsequently the use of the `[[maybe_unused]]` attribute triggers a `-Wc++17-extensions` warning (which we elevate to an error via `-pedantic-errors`). This is observed in the macOS Travis CI environment, where we use Apple Clang: https://app.travis-ci.com/github/tanzislam/cryptopals/jobs/625697125 A similar Clang issue with a different C++17 attribute was also observed in nlohmann/json#1535.
google/googletest@5a37b517ad introduced a check on `__has_cpp_attribute(maybe_unused)`. Under Clang it evaluates to true even in `-std=c++14` mode, but subsequently the use of the `[[maybe_unused]]` attribute triggers a `-Wc++17-extensions` warning which we elevate to an error via `-pedantic-errors`. This was observed in Termux and in the macOS Travis CI environment, where we use Apple Clang: https://app.travis-ci.com/github/tanzislam/cryptopals/jobs/625697125 Interestingly, attempting to downgrade that error back to a warning with `-Wno-error=c++17-extensions` did not work. A similar Clang issue with a different C++17 attribute was also observed in nlohmann/json#1535.
When compiling on Clang (tested 3.9.1 - 7.0.0) with the following compiler flags:
-Wpedantic -std=c++11
Clang displays warnings about:
warning: use of the 'nodiscard' attribute is a C++17 extension [-Wc++17-extensions]
Full log:
Compile json.hpp (3.6.1) using Clang (tested 3.9.1 - 7.0.0) with the following compiler flags:
-Wpedantic -std=c++11
Compilation succeeds without error / warning?
See above.
Clang (tested 3.9.1 - 7.0.0)
develop
branch?Release 3.6.1
The text was updated successfully, but these errors were encountered: