Skip to content

INT64_MIN/MAX not defined for newer g++ #3722

Closed
@billpriest

Description

@billpriest

Description

While cross compiling for arm w/ newer versions of g++ INT64_MAX, INT64_MIN, UINT64, INT32_MIN, INT32_MAX, UINT32_MAX aren't defined. I found the following:
/* The ISO C99 standard specifies that in C++ implementations these
macros should only be defined if explicitly requested. */
#if !defined __cplusplus || defined __STDC_LIMIT_MACROS

Rather than adding the #define to make this work I created a patch that uses the std::numeric_limits<int64_t>::max()
I guess a "compatibility" include file could be created to work around this issue; but it wasn't obvious to me how to do this.

After applying the patch I ran all the tests and they all passed.
int64_min_max.patch.txt

Reproduction steps

git clone https://github.com/nlohmann/json.git
cd json
git checkout v3.11.2
mkdir build
cd build
cmake -DCMAKE_TOOLCHAIN_FILE=../../aarch64.cmake -DCMAKE_INSTALL_PREFIX=/opt/nxpimx8/usr/local ..
make

Expected vs. actual results

See compiler errors below.

Minimal code example

No response

Error messages

json/tests/src/unit-to_chars.cpp:466:23: error: 'INT64_MIN' was not declared in this scope
  466 |         check_integer(INT64_MIN, "-9223372036854775808");
      |                       ^~~~~~~~~
/home/priestwilliaml/newbuild/build/json/tests/src/unit-to_chars.cpp:467:23: error: 'INT64_MAX' was not declared in this scope
  467 |         check_integer(INT64_MAX, "9223372036854775807");
      |                       ^~~~~~~~~

json/tests/src/unit-cbor.cpp: In function 'void _DOCTEST_ANON_FUNC_7()':
/home/priestwilliaml/newbuild/build/json/tests/src/unit-cbor.cpp:176:39: error: 'INT64_MIN' was not declared in this scope
  176 |                     numbers.push_back(INT64_MIN);
      |                                       ^~~~~~~~~

json/tests/src/unit-msgpack.cpp:511:39: error: 'INT64_MIN' was not declared in this scope
  511 |                     numbers.push_back(INT64_MIN);
      |                                       ^~~~~~~~~

json/tests/src/unit-regression1.cpp: In function 'void _DOCTEST_ANON_FUNC_7()':
/home/priestwilliaml/newbuild/build/json/tests/src/unit-regression1.cpp:880:51: error: 'INT64_MIN' was not declared in this scope
  880 |         CHECK(j1.get<json::number_integer_t>() == INT64_MIN);
      |                                                   ^~~~~~~~~

Compiler and operating system

linux g++ 11.2.0 crosscompiling for ARM 64

Library version

v3.11.2 from github

Validation

Metadata

Metadata

Assignees

No one assigned

    Labels

    kind: bugsolution: proposed fixa fix for the issue has been proposed and waits for confirmation

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions