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

C++ compilation error with g++15 caused by including <cstdint> but using int64_t instead of std::int64_t #691

Open
DominiquePelle-TomTom opened this issue Apr 4, 2025 · 2 comments
Labels
bug Something isn't working
Milestone

Comments

@DominiquePelle-TomTom
Copy link

DominiquePelle-TomTom commented Apr 4, 2025

Zserio version and language
Zserio: 2.16.0
Language: C++

Describe the bug

Generated C++ code includes <cstdint> but uses types like uint64_t, int64_t (etc.) without the std:: namespace prefix. This is incorrect and not portable. It causes compilation errors when building with gcc15 such as:

/home/dope/.conan/data/zserio/2.16.0/_/_/build/2a1643475ff774383687d1e8922f3bc3015406f5/src/compiler/extensions/cpp/runtime/src/zserio/JsonEncoder.h: In static member function ‘static void zserio::JsonEncoder::encodeIntegral(std::ostream&, T)’:
/home/dope/.conan/data/zserio/2.16.0/_/_/build/2a1643475ff774383687d1e8922f3bc3015406f5/src/compiler/extensions/cpp/runtime/src/zserio/JsonEncoder.h:67:76: error: ‘uint64_t’ was not declared in this scope [-Wtemplate-body]
   67 |     using U = typename std::conditional<std::is_signed<T>::value, int64_t, uint64_t>::type;
      |                                                                            ^~~~~~~~

To fix it, either:

  • use #include <cstdint> and std::uint64_t in zserio code (preferred and more modern solution, but you have to replace many int64_t into std::int64_t, same for other types like int8_t, etc.)
  • or use #include <stdint.h> and int64_t in zserio code. This is the less preferred and is the old pre-c++11 way. Since it does not use namespace, it is more prone to name collisions.

How to reproduce
N/A

Expected behavior
Generated C++ code should compile on any compiler

@DominiquePelle-TomTom DominiquePelle-TomTom added the bug Something isn't working label Apr 4, 2025
@mikir mikir added this to the 2.17 milestone Apr 7, 2025
@mikir
Copy link
Contributor

mikir commented Apr 7, 2025

Thanks for the report. Currently, we directly support only g++7 and g++11. We should investigate this to understand clearly the differencies between gcc versions.

I will put this issue to the current milestone. However, we are working on C++17 generator now, so it will take some time. If this issue is urgent, please write us a note here. Thanks.

@DominiquePelle-TomTom
Copy link
Author

g++7 and g++11.

Well, the issue is clear enough even if you do not use gcc-15 anyway:

  • if you include (which is the case in zserio source code), then you have to use std::int64_t (not int64_t)
  • if you include <stdint.h>, then you have to use int64_t (not std::int64_t)

Same for other types obviously (std::int8_t, std::uint8_t, etc.)

So it's quite trivial to fix, i.e. replace types such as int64_t with std::int64_t.

If this issue is urgent, please write us a note here

The issue is not urgent for me. Our current toolchain builds successfully, but I noticed the issue when trying to build with gcc-15 (which is not officially used yet in my company).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants