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:
json.hpp:13087:5: error: use of the 'nodiscard' attribute is a C++17 extension [-Werror,-Wc++17-extensions]
JSON_NODISCARD
^
json.hpp:496:34: note: expanded from macro 'JSON_NODISCARD'
#define JSON_NODISCARD [[nodiscard]]
^
json.hpp:14262:5: error: use of the 'nodiscard' attribute is a C++17 extension [-Werror,-Wc++17-extensions]
JSON_NODISCARD
^
json.hpp:496:34: note: expanded from macro 'JSON_NODISCARD'
#define JSON_NODISCARD [[nodiscard]]
^
json.hpp:14306:5: error: use of the 'nodiscard' attribute is a C++17 extension [-Werror,-Wc++17-extensions]
JSON_NODISCARD
^
json.hpp:496:34: note: expanded from macro 'JSON_NODISCARD'
#define JSON_NODISCARD [[nodiscard]]
^
json.hpp:18858:5: error: use of the 'nodiscard' attribute is a C++17 extension [-Werror,-Wc++17-extensions]
JSON_NODISCARD
^
json.hpp:496:34: note: expanded from macro 'JSON_NODISCARD'
#define JSON_NODISCARD [[nodiscard]]
^
json.hpp:19627:5: error: use of the 'nodiscard' attribute is a C++17 extension [-Werror,-Wc++17-extensions]
JSON_NODISCARD
^
json.hpp:496:34: note: expanded from macro 'JSON_NODISCARD'
#define JSON_NODISCARD [[nodiscard]]
^
json.hpp:19643:5: error: use of the 'nodiscard' attribute is a C++17 extension [-Werror,-Wc++17-extensions]
JSON_NODISCARD
^
json.hpp:496:34: note: expanded from macro 'JSON_NODISCARD'
#define JSON_NODISCARD [[nodiscard]]
^
json.hpp:19736:5: error: use of the 'nodiscard' attribute is a C++17 extension [-Werror,-Wc++17-extensions]
JSON_NODISCARD
^
json.hpp:496:34: note: expanded from macro 'JSON_NODISCARD'
#define JSON_NODISCARD [[nodiscard]]
^
json.hpp:19752:5: error: use of the 'nodiscard' attribute is a C++17 extension [-Werror,-Wc++17-extensions]
JSON_NODISCARD
^
json.hpp:496:34: note: expanded from macro 'JSON_NODISCARD'
#define JSON_NODISCARD [[nodiscard]]
^
json.hpp:19824:5: error: use of the 'nodiscard' attribute is a C++17 extension [-Werror,-Wc++17-extensions]
JSON_NODISCARD
^
json.hpp:496:34: note: expanded from macro 'JSON_NODISCARD'
#define JSON_NODISCARD [[nodiscard]]
^
json.hpp:19840:5: error: use of the 'nodiscard' attribute is a C++17 extension [-Werror,-Wc++17-extensions]
JSON_NODISCARD
^
json.hpp:496:34: note: expanded from macro 'JSON_NODISCARD'
#define JSON_NODISCARD [[nodiscard]]
^
json.hpp:19911:5: error: use of the 'nodiscard' attribute is a C++17 extension [-Werror,-Wc++17-extensions]
JSON_NODISCARD
^
json.hpp:496:34: note: expanded from macro 'JSON_NODISCARD'
#define JSON_NODISCARD [[nodiscard]]
^
json.hpp:19927:5: error: use of the 'nodiscard' attribute is a C++17 extension [-Werror,-Wc++17-extensions]
JSON_NODISCARD
^
json.hpp:496:34: note: expanded from macro 'JSON_NODISCARD'
#define JSON_NODISCARD [[nodiscard]]
^
json.hpp:20516:5: error: use of the 'nodiscard' attribute is a C++17 extension [-Werror,-Wc++17-extensions]
JSON_NODISCARD
^
json.hpp:496:34: note: expanded from macro 'JSON_NODISCARD'
#define JSON_NODISCARD [[nodiscard]]
^
13 errors generated.
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 library checks whether the nodiscard attribute is available. Apparently, Clang reports it being available in C++11 mode, but then -Wc++17-extensions warns that it is a C++17 feature. This seems odd.
A solution could be to make the check more restrictive and switch off nodiscard unless C++17 is detected. I don't really like this. Alternatively, we could suppress the warning in the library. This is also not nice... Any opinions?
A solution could be to make the check more restrictive and switch off
nodiscardunless C++17 is detected. I don't really like this.
Me neither.
Alternatively, we could suppress the warning in the library. This is also not nice... Any opinions?
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 -Wc++1z-extensions, and is an alias for -Wc++17-extensions on newer Clang versions.
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 -std=c++11/c++14 cannot enjoy warnings from [[nodiscard]]. It should be fine because nodiscard is supposed to be available since c++17. Users have an option to use -std=c++17 if they really want it.
If the second option is taken, the developers of this library cannot enjoy warnings from -Wc++17-extensions. It potentially makes the development process more error prone.
#if __has_cpp_attribute(nodiscard)
#if defined(__clang__) && !defined(JSON_HAS_CPP_17) // issue #1535
#define JSON_NODISCARD
#else
#define JSON_NODISCARD [[nodiscard]]
#endif
馃敄 release item in #1551.
Most helpful comment
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
-std=c++11/c++14cannot enjoy warnings from[[nodiscard]]. It should be fine becausenodiscardis supposed to be available since c++17. Users have an option to use-std=c++17if they really want it.If the second option is taken, the developers of this library cannot enjoy warnings from
-Wc++17-extensions. It potentially makes the development process more error prone.