From 30ec0541d55d048467ad5de9a9718d89ad6c8c35 Mon Sep 17 00:00:00 2001 From: Robin Haberkorn Date: Mon, 3 Nov 2025 20:06:45 +1100 Subject: Support ptrdiff_t if it has the same storage size as int, but does *not* alias it * This is the case e.g. on NetBSD 10 for ARMv6 where Sci::Position == ptrdiff_t == long int, but obviously for other platforms as well, where it causes "invalid conversion" and "undefined symbol" errors. Scintilla was testing for aliasability by comparing the storage size with sizeof() or PTRDIFF_MAX == INT_MAX at the preprocessor level. This was fundamentally flawed. * In LineVector::InsertLines() we are now using the C++17 construct std::is_convertible_v instead. * We need RunStyles as well on the affected platforms. This is impossible to test for in a constant expression that can be used with the preprocessor. Also, it's not possible to conditionally instantiate templates. We tried to instantiate RunStyles for all scalar types that could be behind ptrdiff_t, but it was causing warnings on MSVC. Implicitly instantiating RunStyles would be possible, but is not desired. Therefore as a workaround, you can now define the PTRDIFF_DOESNT_ALIAS_INT macro when invoking the build system, to force instantiating RunStyles. When writing portable applications, you may have to use a compile-time check for checking aliasability of ptrdiff_t and int in order to define PTRDIFF_DOESNT_ALIAS_INT. --- src/CellBuffer.cxx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/CellBuffer.cxx') diff --git a/src/CellBuffer.cxx b/src/CellBuffer.cxx index 04486d4c6..3e9deb934 100644 --- a/src/CellBuffer.cxx +++ b/src/CellBuffer.cxx @@ -21,6 +21,7 @@ #include #include #include +#include #include "ScintillaTypes.h" @@ -215,7 +216,7 @@ public: } void InsertLines(Sci::Line line, const Sci::Position *positions, size_t lines, bool lineStart) override { const POS lineAsPos = pos_cast(line); - if constexpr (sizeof(Sci::Position) == sizeof(POS)) { + if constexpr (std::is_convertible_v) { starts.InsertPartitions(lineAsPos, positions, lines); } else { starts.InsertPartitionsWithCast(lineAsPos, positions, lines); -- cgit v1.2.3