From: https://github.com/bpftrace/bpftrace/pull/4614

From: =?UTF-8?q?Holger=20Hoffst=C3=A4tte?= <holger@applied-asynchrony.com>
Date: Thu, 18 Sep 2025 11:55:36 +0200
Subject: [PATCH] build: fix building with gcc-16
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Gcc-16 has once again tightened some transitive includes, which
means some headers must now be explicitly included.
For example:

  src/util/int_parser.cpp: In function ‘bpftrace::Result<long unsigned int> bpftrace::util::to_uint(const std::string&, int)’:
  src/util/int_parser.cpp:70:14: error: ‘ULLONG_MAX’ was not declared in this scope
     70 |   if (ret == ULLONG_MAX && errno == ERANGE) {
        |              ^~~~~~~~~~
  src/util/int_parser.cpp:8:1: note: ‘ULLONG_MAX’ is defined in header ‘<climits>’; this is probably fixable by adding ‘#include <climits>’
      7 | #include "util/int_parser.h"
    +++ |+#include <climits>
      8 | #include "util/result.h"

Tested with gcc-15.2.1-20250913, gcc-16.0.0-20250914 & clang-21.1.1.

Signed-off-by: Holger Hoffstätte <holger@applied-asynchrony.com>
---
 src/util/int_parser.cpp | 2 +-
 src/util/opaque.h       | 1 +
 tests/utils.cpp         | 1 +
 3 files changed, 3 insertions(+), 1 deletion(-)

diff --git a/src/util/int_parser.cpp b/src/util/int_parser.cpp
index c88e034a..ad8f98a2 100644
--- a/src/util/int_parser.cpp
+++ b/src/util/int_parser.cpp
@@ -1,5 +1,5 @@
+#include <climits>
 #include <cstdint>
-#include <limits>
 #include <map>
 #include <optional>
 #include <ranges>
diff --git a/src/util/opaque.h b/src/util/opaque.h
index 1e8cf1bd..9b20a96b 100644
--- a/src/util/opaque.h
+++ b/src/util/opaque.h
@@ -1,5 +1,6 @@
 #pragma once
 
+#include <cstdint>
 #include <cstdlib>
 #include <cstring>
 #include <functional>
diff --git a/tests/utils.cpp b/tests/utils.cpp
index 91d56347..10116ad4 100644
--- a/tests/utils.cpp
+++ b/tests/utils.cpp
@@ -1,3 +1,4 @@
+#include <climits>
 #include <cstdlib>
 #include <cstring>
 #include <fcntl.h>
-- 
2.51.0

