Skip to content

Annoying -Wundef on new JSON_DIAGNOSTICS macro #2975

Closed
@gcerretani

Description

@gcerretani

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

Metadata

Metadata

Assignees

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions