From c4c4d320b9a7c18760cfb22dfb1dd228c4fdf36d Mon Sep 17 00:00:00 2001 From: Andrew Johnson Date: Sun, 20 Sep 2026 12:29:41 +0800 Subject: [PATCH 1/2] Fix macos size_t ambiguity --- src/stan/callbacks/json_writer.hpp | 17 ++++++++++------- src/stan/callbacks/structured_writer.hpp | 18 ++++++++++-------- src/test/unit/callbacks/json_writer_test.cpp | 17 +++++++++++++++++ 3 files changed, 37 insertions(+), 15 deletions(-) diff --git a/src/stan/callbacks/json_writer.hpp b/src/stan/callbacks/json_writer.hpp index b13f6fb14b3..09f70575294 100644 --- a/src/stan/callbacks/json_writer.hpp +++ b/src/stan/callbacks/json_writer.hpp @@ -296,12 +296,15 @@ class json_writer final : public structured_writer { */ void write(const std::string& key, int value) { write_int_like(key, value); } - /** - * Write a key-value pair where the value is an `std::size_t`. - * @param key Name of the value pair - * @param value `std::size_t` to write. - */ - void write(const std::string& key, std::size_t value) { + /// Write a key-value pair with an unsigned long value. + void write(const std::string& key, + unsigned long value) override { // NOLINT(runtime/int) + write_int_like(key, value); + } + + /// Write a key-value pair with an unsigned long long value. + void write(const std::string& key, + unsigned long long value) override { // NOLINT(runtime/int) write_int_like(key, value); } @@ -321,7 +324,7 @@ class json_writer final : public structured_writer { * @param key Name of the value pair * @param value `unsigned int` to write. */ - void write(const std::string& key, unsigned int value) { + void write(const std::string& key, unsigned int value) override { write_int_like(key, value); } diff --git a/src/stan/callbacks/structured_writer.hpp b/src/stan/callbacks/structured_writer.hpp index 5af3b54202b..0e97d560746 100644 --- a/src/stan/callbacks/structured_writer.hpp +++ b/src/stan/callbacks/structured_writer.hpp @@ -1,7 +1,6 @@ #ifndef STAN_CALLBACKS_STRUCTURED_WRITER_HPP #define STAN_CALLBACKS_STRUCTURED_WRITER_HPP -#include #include #include #include @@ -65,12 +64,15 @@ class structured_writer { */ virtual void write(const std::string& key, int value) {} - /** - * Write a key-value pair where the value is an `uint64_t`. - * @param key Name of the value pair - * @param value `uint64_t` to write. - */ - virtual void write(const std::string& key, uint64_t value) {} + /// Write a key-value pair with an unsigned long value. + virtual void write(const std::string& key, + unsigned long value // NOLINT(runtime/int) + ) {} + + /// Write a key-value pair with an unsigned long long value. + virtual void write(const std::string& key, + unsigned long long value // NOLINT(runtime/int) + ) {} /** * Write a key-value pair where the value is an `long long int`. @@ -86,7 +88,7 @@ class structured_writer { * @param key Name of the value pair * @param value `unsigned int` to write. */ - virtual void write(const std::string& key, uint32_t value) {} + virtual void write(const std::string& key, unsigned int value) {} /** * Write a key-value pair where the value is a double. diff --git a/src/test/unit/callbacks/json_writer_test.cpp b/src/test/unit/callbacks/json_writer_test.cpp index af589637b8d..041b0095e24 100644 --- a/src/test/unit/callbacks/json_writer_test.cpp +++ b/src/test/unit/callbacks/json_writer_test.cpp @@ -1,6 +1,8 @@ #include #include #include +#include +#include #include struct deleter_noop { @@ -38,6 +40,21 @@ TEST_F(StanInterfaceCallbacksJsonWriter, begin_end_record) { EXPECT_EQ("{}", out); } +TEST_F(StanInterfaceCallbacksJsonWriter, write_unsigned_through_base) { + stan::callbacks::structured_writer& base = writer; + base.begin_record(); + base.write("uint", 42U); + base.write("ulong", 4294967295UL); + base.write("ullong", 18446744073709551615ULL); + base.write("size", std::size_t{5}); + base.write("uint64", std::numeric_limits::max()); + base.end_record(); + EXPECT_EQ("{\"uint\":42,\"ulong\":4294967295," + "\"ullong\":18446744073709551615,\"size\":5," + "\"uint64\":18446744073709551615}", + output_sans_whitespace(ss)); +} + TEST_F(StanInterfaceCallbacksJsonWriter, begin_end_named_record) { writer.begin_record(); writer.begin_record("name"); From 3713d54620e28e050f4e26633fc29eaebb9b04ba Mon Sep 17 00:00:00 2001 From: Stan Jenkins Date: Sun, 20 Sep 2026 00:35:36 -0400 Subject: [PATCH 2/2] [Jenkins] auto-formatting by clang-format version 10.0.0-4ubuntu1 --- src/test/unit/callbacks/json_writer_test.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/test/unit/callbacks/json_writer_test.cpp b/src/test/unit/callbacks/json_writer_test.cpp index 041b0095e24..1bf61f375b0 100644 --- a/src/test/unit/callbacks/json_writer_test.cpp +++ b/src/test/unit/callbacks/json_writer_test.cpp @@ -49,10 +49,11 @@ TEST_F(StanInterfaceCallbacksJsonWriter, write_unsigned_through_base) { base.write("size", std::size_t{5}); base.write("uint64", std::numeric_limits::max()); base.end_record(); - EXPECT_EQ("{\"uint\":42,\"ulong\":4294967295," - "\"ullong\":18446744073709551615,\"size\":5," - "\"uint64\":18446744073709551615}", - output_sans_whitespace(ss)); + EXPECT_EQ( + "{\"uint\":42,\"ulong\":4294967295," + "\"ullong\":18446744073709551615,\"size\":5," + "\"uint64\":18446744073709551615}", + output_sans_whitespace(ss)); } TEST_F(StanInterfaceCallbacksJsonWriter, begin_end_named_record) {