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

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

Closed
2 tasks done
billpriest opened this issue Sep 4, 2022 · 2 comments · Fixed by #3723
Closed
2 tasks done

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

billpriest opened this issue Sep 4, 2022 · 2 comments · Fixed by #3723
Labels
kind: bug solution: proposed fix a fix for the issue has been proposed and waits for confirmation

Comments

@billpriest
Copy link

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

@falbrechtskirchinger
Copy link
Contributor

We should be using std::numeric_limits anyway.

@falbrechtskirchinger
Copy link
Contributor

falbrechtskirchinger commented Sep 13, 2022

INT64_MIN/MAX not defined for newer g++

The problem is usually older compilers (or standard libraries, technically). C++11 (and C11) removed the need for __STDC_LIMIT_MACROS.

#if (!defined __cplusplus || __cplusplus >= 201103L \
     || defined __STDC_LIMIT_MACROS)

Even after replacing these limit macros, we still depend on SIZE_MAX for conditional code and can't easily replace those uses with std::numeric_limits because of enabled compiler warnings.

I wonder why your compiler doesn't seem to complain about that? (SIZE_MAX is defined within the same conditional block in my header files.)

@nlohmann nlohmann added the solution: proposed fix a fix for the issue has been proposed and waits for confirmation label Sep 19, 2022
@nlohmann nlohmann added this to the Release 3.11.3 milestone Sep 19, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind: bug 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.

3 participants