Skip to content
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

Annoying -Wundef on new JSON_DIAGNOSTICS macro #2975

Closed
1 of 5 tasks
gcerretani opened this issue Aug 25, 2021 · 2 comments · Fixed by #2976
Closed
1 of 5 tasks

Annoying -Wundef on new JSON_DIAGNOSTICS macro #2975

gcerretani opened this issue Aug 25, 2021 · 2 comments · Fixed by #2976
Assignees
Labels
confirmed kind: bug release item: 🔨 further change solution: proposed fix a fix for the issue has been proposed and waits for confirmation

Comments

@gcerretani
Copy link
Contributor

gcerretani commented Aug 25, 2021

A new convenience macro JSON_DIAGNOSTICS has been introduced on v3.10.0. If not defiend, lots of -Wundef warning are reported.

What is the issue you have?

JSON_DIAGNOSTICS macro is used in preprocessor directives like:

#if JSON_DIAGNOSTICS
// stuff
#endif

It is legal, as stated here on cppreference.com:

#if, #elif
The expression is a constant expression, using only constants and identifiers, defined using #define directive. Any identifier, which is not literal, non defined using #define directive, evaluates to 0.

However, GCC reports tons of warnings is executed with -Wundef, like:

[...]/json/include/nlohmann/detail/exceptions.hpp:73:5: warning: "JSON_DIAGNOSTICS" is not defined, evaluates to 0 [-Wundef]
 #if JSON_DIAGNOSTICS
     ^~~~~~~~~~~~~~~~

Not sure if it is a bug or not, but the "evaluates to 0" preprocessor rule usage is very rare.

Please describe the steps to reproduce the issue.

  1. Compile any project with any GCC version with -Wundef

Can you provide a small but working code example?

#include <nlohmann/json.hpp>

What is the expected behavior?

No warning.

And what is the actual behavior instead?

Warnings!

Which compiler and operating system are you using?

  • Compiler: Any GCC or clang version
  • Operating system: Linux

Which version of the library did you use?

  • latest release version 3.10.1
  • other release - please state the version: 3.10.0
  • the develop branch

If you experience a compilation error: can you compile and run the unit tests?

  • yes
  • no - please copy/paste the error message below
@gcerretani
Copy link
Contributor Author

It could be safely fixed by adding

#ifndef JSON_DIAGNOSTICS
#define JSON_DIAGNOSTICS 0
#endif

somewhere at the beginning of the header.

gcerretani added a commit to gcerretani/json that referenced this issue Aug 25, 2021
Define JSON_DIAGNOSTICS to 0 if not defined to fix annoying Wundef warnings.
@nlohmann
Copy link
Owner

I can confirm the issue. The reason we did not detect this is that we define

JSON_DIAGNOSTICS=$<BOOL:${JSON_Diagnostics}>

in the CMake build which we use in the CI. That is, the warning only occurs when building without CMake. It was an oversight not to treat JSON_DIAGNOSTICS like JSON_USE_IMPLICIT_CONVERSIONS for which we had the code

#ifndef JSON_USE_IMPLICIT_CONVERSIONS
    #define JSON_USE_IMPLICIT_CONVERSIONS 1
#endif

@nlohmann nlohmann added solution: proposed fix a fix for the issue has been proposed and waits for confirmation release item: 🔨 further change labels Aug 25, 2021
@nlohmann nlohmann self-assigned this Aug 25, 2021
@nlohmann nlohmann added this to the Release 3.10.2 milestone Aug 25, 2021
nlohmann pushed a commit that referenced this issue Aug 26, 2021
* Fix #2975

Define JSON_DIAGNOSTICS to 0 if not defined to fix annoying Wundef warnings.

* amalgamated
kraj pushed a commit to YoeDistro/meta-openembedded that referenced this issue Sep 6, 2021
Release date: 2021-08-26
SHA-256: 059743e48b37e41579ee3a92e82e984bfa0d2a9a2b20b175d04db8089f46f047 (json.hpp)
61e605be15e88deeac4582aaf01c09d616f8302edde7adcaba9261ddc3b4ceca (include.zip)

Summary
This release is made days after the 3.10.1 release due to a bug in the release script:
The 3.10.1 release at GitHub contained the correct files,
but the associated tag v3.10.1 points to the wrong commit.
This release is made with a fixed build script. All changes are backward-compatible.

Improvements
Fix the release scripts to correctly tag releases. nlohmann/json#2973
Fix some -Wunused warnings on JSON_DIAGNOSTICS when the library is built without CMake.
nlohmann/json#2975
nlohmann/json#2976

Deprecated functions
Passing iterator pairs or pointer/length pairs to parsing functions
(basic_json::parse, basic_json::accept, basic_json::sax_parse, basic_json::from_cbor,
basic_json::from_msgpack, basic_json::from_ubjson, basic_json::from_bson)
via initializer lists is deprecated.
Instead, pass two iterators; for instance, call basic_json::from_cbor(ptr, ptr+len)
instead of basic_json::from_cbor({ptr, len}).

-License-Update: Copyright year updated to 2021.

Signed-off-by: Wang Mingyu <wangmy@fujitsu.com>
Signed-off-by: Khem Raj <raj.khem@gmail.com>
daregit pushed a commit to daregit/yocto-combined that referenced this issue May 22, 2024
Release date: 2021-08-26
SHA-256: 059743e48b37e41579ee3a92e82e984bfa0d2a9a2b20b175d04db8089f46f047 (json.hpp)
61e605be15e88deeac4582aaf01c09d616f8302edde7adcaba9261ddc3b4ceca (include.zip)

Summary
This release is made days after the 3.10.1 release due to a bug in the release script:
The 3.10.1 release at GitHub contained the correct files,
but the associated tag v3.10.1 points to the wrong commit.
This release is made with a fixed build script. All changes are backward-compatible.

Improvements
Fix the release scripts to correctly tag releases. nlohmann/json#2973
Fix some -Wunused warnings on JSON_DIAGNOSTICS when the library is built without CMake.
nlohmann/json#2975
nlohmann/json#2976

Deprecated functions
Passing iterator pairs or pointer/length pairs to parsing functions
(basic_json::parse, basic_json::accept, basic_json::sax_parse, basic_json::from_cbor,
basic_json::from_msgpack, basic_json::from_ubjson, basic_json::from_bson)
via initializer lists is deprecated.
Instead, pass two iterators; for instance, call basic_json::from_cbor(ptr, ptr+len)
instead of basic_json::from_cbor({ptr, len}).

-License-Update: Copyright year updated to 2021.

Signed-off-by: Wang Mingyu <wangmy@fujitsu.com>
Signed-off-by: Khem Raj <raj.khem@gmail.com>
daregit pushed a commit to daregit/yocto-combined that referenced this issue May 22, 2024
Release date: 2021-08-26
SHA-256: 059743e48b37e41579ee3a92e82e984bfa0d2a9a2b20b175d04db8089f46f047 (json.hpp)
61e605be15e88deeac4582aaf01c09d616f8302edde7adcaba9261ddc3b4ceca (include.zip)

Summary
This release is made days after the 3.10.1 release due to a bug in the release script:
The 3.10.1 release at GitHub contained the correct files,
but the associated tag v3.10.1 points to the wrong commit.
This release is made with a fixed build script. All changes are backward-compatible.

Improvements
Fix the release scripts to correctly tag releases. nlohmann/json#2973
Fix some -Wunused warnings on JSON_DIAGNOSTICS when the library is built without CMake.
nlohmann/json#2975
nlohmann/json#2976

Deprecated functions
Passing iterator pairs or pointer/length pairs to parsing functions
(basic_json::parse, basic_json::accept, basic_json::sax_parse, basic_json::from_cbor,
basic_json::from_msgpack, basic_json::from_ubjson, basic_json::from_bson)
via initializer lists is deprecated.
Instead, pass two iterators; for instance, call basic_json::from_cbor(ptr, ptr+len)
instead of basic_json::from_cbor({ptr, len}).

-License-Update: Copyright year updated to 2021.

Signed-off-by: Wang Mingyu <wangmy@fujitsu.com>
Signed-off-by: Khem Raj <raj.khem@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
confirmed kind: bug release item: 🔨 further change solution: proposed fix a fix for the issue has been proposed and waits for confirmation
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants