Skip to content

PR Replacement #13185: refactor : Fix compilation errors in TextView.h by removing ambiguous constructor overloads and revised TextView.cc header includes#13187

Open
grahamsedman wants to merge 2 commits into
apache:masterfrom
grahamsedman:fix/lib-swoc-textview-constructors
Open

PR Replacement #13185: refactor : Fix compilation errors in TextView.h by removing ambiguous constructor overloads and revised TextView.cc header includes#13187
grahamsedman wants to merge 2 commits into
apache:masterfrom
grahamsedman:fix/lib-swoc-textview-constructors

Conversation

@grahamsedman
Copy link
Copy Markdown

@grahamsedman grahamsedman commented May 21, 2026

Note: This replaces PR #13185. The branch has been renamed to fix/lib-swoc-textview-constructors to maintain consistent local branch organisation for my own folk.

This PR fixes build failures occurring on 32-bit architectures (specifically arm-linux-gnueabihf). Ensure both 32 bit and 64 bit targets are catered for in the refactor.

Problem

On 32-bit systems, size_t is defined as unsigned int and ssize_t is defined as int. The TextView class currently defines distinct constructor overloads for size_t, unsigned, ssize_t, and int.

This results in duplicate function signatures on 32-bit builds, causing the compiler to throw constructor cannot be redeclared errors.

Errors observed:

error: constructor cannot be redeclared
  constexpr TextView(char const *ptr, unsigned n) noexcept;
            ^
note: previous declaration is here
  constexpr TextView(char const *ptr, size_t n) noexcept;

Solution

To resolve this ambiguity, this PR refactors the constructor overloads to rely only on size_t and int.

  • Removed: TextView(char const *ptr, unsigned n)
  • Removed: TextView(char const *ptr, ssize_t n)
  • Retained: TextView(char const *ptr, size_t n) (Covers unsigned on 32-bit and size_t on 64-bit)
  • Retained: TextView(char const *ptr, int n) (Covers ssize_t on 32-bit and int on 64-bit)

The logic within the retained constructors (specifically handling n < 0 for int) remains unchanged, ensuring functional parity across architectures.

Changes

Checklist:

Compilation Errors

/home/grahamsedman/Projects/trafficserver/lib/swoc/include/swoc/TextView.h:122:13: error: constructor cannot be redeclared
122 | constexpr TextView(char const *ptr, unsigned n) noexcept;
| ^
/home/grahamsedman/Projects/trafficserver/lib/swoc/include/swoc/TextView.h:115:13: note: previous declaration is here
115 | constexpr TextView(char const *ptr, size_t n) noexcept;
| ^
/home/grahamsedman/Projects/trafficserver/lib/swoc/include/swoc/TextView.h:142:13: error: constructor cannot be redeclared
142 | constexpr TextView(char const *ptr, int n) noexcept;
| ^
/home/grahamsedman/Projects/trafficserver/lib/swoc/include/swoc/TextView.h:132:13: note: previous declaration is here
132 | constexpr TextView(char const *ptr, ssize_t n) noexcept;
| ^
/home/grahamsedman/Projects/trafficserver/lib/swoc/include/swoc/TextView.h:1128:28: error: redefinition of 'TextView'
1128 | inline constexpr TextView::TextView(const char *ptr, unsigned n) noexcept : super_type(ptr, size_t(n)) {}
| ^
/home/grahamsedman/Projects/trafficserver/lib/swoc/include/swoc/TextView.h:1126:28: note: previous definition is here
1126 | inline constexpr TextView::TextView(const char *ptr, size_t n) noexcept
| ^
/home/grahamsedman/Projects/trafficserver/lib/swoc/include/swoc/TextView.h:1131:28: error: redefinition of 'TextView'
1131 | inline constexpr TextView::TextView(const char *ptr, int n) noexcept
| ^
/home/grahamsedman/Projects/trafficserver/lib/swoc/include/swoc/TextView.h:1129:28: note: previous definition is here
1129 | inline constexpr TextView::TextView(const char *ptr, ssize_t n) noexcept

Add missing standard library headers required for compilation, such as
<algorithm>, <cstring>, <cctype>, <strings.h>, <sys/types.h>, <ostream>,
and <limits>. Reorder existing includes for better organisation.

Apply consistent indentation and formatting style (placing opening
braces on new lines) to the entire file to improve readability and
adherence to style guidelines. Remove redundant TextView constructor
overloads taking unsigned and ssize_t to simplify the interface and
reduce ambiguity. Update namespace closing comments to reflect the new
brace style.
Update the source code style and remove unnecessary header dependencies.

* Adjust indentation for the contents of the swoc and SWOC_VERSION_NS
namespaces.
* Move opening braces for functions and namespaces to new lines.
* Remove unused <cctype> and <sstream> includes.
@grahamsedman grahamsedman changed the title PR Replacement #13185: Fix 32-bit compilation errors in TextView.h by removing ambiguous constructor overloads and revised TextView.cc header includes PR Replacement #13185: Fix compilation errors in TextView.h by removing ambiguous constructor overloads and revised TextView.cc header includes May 22, 2026
@grahamsedman grahamsedman changed the title PR Replacement #13185: Fix compilation errors in TextView.h by removing ambiguous constructor overloads and revised TextView.cc header includes PR Replacement #13185: refactor : Fix compilation errors in TextView.h by removing ambiguous constructor overloads and revised TextView.cc header includes May 24, 2026
@grahamsedman
Copy link
Copy Markdown
Author

grahamsedman commented May 25, 2026

Hi,

I noticed this PR is failing the Jenkins AuTest stages. I investigated the failure, and it is not related to my code changes.

The tests/prepare_proxy_verifier.sh script has a hardcoded SHA1 hash on line 44:
expected_sha1="e11b5867a56c5ffd496b18c901f1273e9c120a47"

The tarball hosted at https://ci.trafficserver.apache.org/bintray/proxy-verifier-v3.1.2.tar.gz has apparently been repackaged. I downloaded the tarball locally, and the new correct SHA1 hash is:**
0a60c646cbc9326abb2fbc397cb9efa8c08a807a

Could a maintainer please update line 44 in prepare_proxy_verifier.sh on the master branch with this new hash? Once that is fixed, I believe this PR will pass CI.

Thank you!

Copy link
Copy Markdown
Contributor

@brbzull0 brbzull0 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi.
Aprox ~10 line change burried into 2k lines changes? very hard to review.

@bneradt
Copy link
Copy Markdown
Contributor

bneradt commented May 26, 2026

Note, we see this in the CI failures:

FAILED: lib/swoc/unit_tests/CMakeFiles/test_libswoc.dir/test_MemArena.cc.o 
/usr/sbin/ccache /usr/sbin/c++ -DDEBUG -DOPENSSL_API_COMPAT=10002 -DOPENSSL_IS_OPENSSL3 -DPACKAGE_NAME="\"Apache Traffic Server\"" -DPACKAGE_VERSION=\"11.0.0\" -D_DEBUG -Dlinux -I/home/jenkins/workspace/Github_Builds/autest/src/include -I/home/jenkins/workspace/Github_Builds/autest/src/build/include -I/home/jenkins/workspace/Github_Builds/autest/src/lib/swoc/include -I/home/jenkins/workspace/Github_Builds/autest/src/lib/Catch2/src/catch2/.. -I/home/jenkins/workspace/Github_Builds/autest/src/build/lib/Catch2/generated-includes -pthread -g -std=c++17 -DENABLE_SYSTEMTAP_PROBES -Wno-invalid-offsetof -Wno-shadow -Wall -Wextra -Werror -Wno-unused-parameter -Wno-format-truncation -Wno-unused-variable -Wno-error=parentheses -Werror -MD -MT lib/swoc/unit_tests/CMakeFiles/test_libswoc.dir/test_MemArena.cc.o -MF lib/swoc/unit_tests/CMakeFiles/test_libswoc.dir/test_MemArena.cc.o.d -o lib/swoc/unit_tests/CMakeFiles/test_libswoc.dir/test_MemArena.cc.o -c /home/jenkins/workspace/Github_Builds/autest/src/lib/swoc/unit_tests/test_MemArena.cc
../lib/swoc/unit_tests/test_MemArena.cc: In function 'void CATCH2_INTERNAL_TEST_12()':
../lib/swoc/unit_tests/test_MemArena.cc:334:15: error: conversion from '<brace-enclosed initializer list>' to 'const swoc::_1_5_15::TextView' is ambiguous
  334 |       localize(*arena, {buffer, n});
      |       ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~
../lib/swoc/unit_tests/test_MemArena.cc:334:15: note: there are 2 candidates
In file included from ../lib/swoc/include/swoc/MemArena.h:23,
                 from ../lib/swoc/unit_tests/test_MemArena.cc:29:
../lib/swoc/include/swoc/TextView.h:1135:20: note: candidate 1: 'constexpr swoc::_1_5_15::TextView::TextView(const char*, int)'
 1135 |   inline constexpr TextView::TextView(const char *ptr, int n) noexcept
      |                    ^~~~~~~~
../lib/swoc/include/swoc/TextView.h:1131:20: note: candidate 2: 'constexpr swoc::_1_5_15::TextView::TextView(const char*, size_t)'
 1131 |   inline constexpr TextView::TextView(const char *ptr, size_t n) noexcept
      |                    ^~~~~~~~
../lib/swoc/unit_tests/test_MemArena.cc:46:43: note: initializing argument 2 of 'swoc::_1_5_15::TextView {anonymous}::localize(swoc::_1_5_15::MemArena&, const swoc::_1_5_15::TextView&)'
   46 | localize(MemArena &arena, TextView const &view) {
      |                           ~~~~~~~~~~~~~~~~^~~~
../lib/swoc/unit_tests/test_MemArena.cc:350:15: error: conversion from '<brace-enclosed initializer list>' to 'const swoc::_1_5_15::TextView' is ambiguous
  350 |       localize(*arena, {buffer, n});
      |       ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~
../lib/swoc/unit_tests/test_MemArena.cc:350:15: note: there are 2 candidates
../lib/swoc/include/swoc/TextView.h:1135:20: note: candidate 1: 'constexpr swoc::_1_5_15::TextView::TextView(const char*, int)'
 1135 |   inline constexpr TextView::TextView(const char *ptr, int n) noexcept
      |                    ^~~~~~~~
../lib/swoc/include/swoc/TextView.h:1131:20: note: candidate 2: 'constexpr swoc::_1_5_15::TextView::TextView(const char*, size_t)'
 1131 |   inline constexpr TextView::TextView(const char *ptr, size_t n) noexcept
      |                    ^~~~~~~~
../lib/swoc/unit_tests/test_MemArena.cc:46:43: note: initializing argument 2 of 'swoc::_1_5_15::TextView {anonymous}::localize(swoc::_1_5_15::MemArena&, const swoc::_1_5_15::TextView&)'
   46 | localize(MemArena &arena, TextView const &view) {
      |                           ~~~~~~~~~~~~~~~~^~~~
../lib/swoc/unit_tests/test_MemArena.cc:365:15: error: conversion from '<brace-enclosed initializer list>' to 'const swoc::_1_5_15::TextView' is ambiguous
  365 |       localize(*arena, {buffer, n});
      |       ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~
../lib/swoc/unit_tests/test_MemArena.cc:365:15: note: there are 2 candidates
../lib/swoc/include/swoc/TextView.h:1135:20: note: candidate 1: 'constexpr swoc::_1_5_15::TextView::TextView(const char*, int)'
 1135 |   inline constexpr TextView::TextView(const char *ptr, int n) noexcept
      |                    ^~~~~~~~
../lib/swoc/include/swoc/TextView.h:1131:20: note: candidate 2: 'constexpr swoc::_1_5_15::TextView::TextView(const char*, size_t)'
 1131 |   inline constexpr TextView::TextView(const char *ptr, size_t n) noexcept
      |                    ^~~~~~~~
../lib/swoc/unit_tests/test_MemArena.cc:46:43: note: initializing argument 2 of 'swoc::_1_5_15::TextView {anonymous}::localize(swoc::_1_5_15::MemArena&, const swoc::_1_5_15::TextView&)'
   46 | localize(MemArena &arena, TextView const &view) {
      |                           ~~~~~~~~~~~~~~~~^~~~
../lib/swoc/unit_tests/test_MemArena.cc: At global scope:
../lib/swoc/unit_tests/test_MemArena.cc:46:1: error: 'swoc::_1_5_15::TextView {anonymous}::localize(swoc::_1_5_15::MemArena&, const swoc::_1_5_15::TextView&)' defined but not used [-Werror=unused-function]
   46 | localize(MemArena &arena, TextView const &view) {
      | ^~~~~~~~
cc1plus: all warnings being treated as errors
[646/1599] /usr/sbin/ccache /usr/sbin/c++ -DDEBUG -DOPENSSL_API_COMPAT=10002 -DOPENSSL_IS_OPENSSL3 -DPACKAGE_NAME="\"Apache Traffic Server\"" -DPACKAGE_VERSION=\"11.0.0\" -D_DEBUG -Dlinux -I/home/jenkins/workspace/Github_Builds/autest/src/include -I/home/jenkins/workspace/Github_Builds/autest/src/build/include -I/home/jenkins/workspace/Github_Builds/autest/src/lib/swoc/include -I/home/jenkins/workspace/Github_Builds/autest/src/lib/Catch2/src/catch2/.. -I/home/jenkins/workspace/Github_Builds/autest/src/build/lib/Catch2/generated-includes -pthread -g -std=c++17 -DENABLE_SYSTEMTAP_PROBES -Wno-invalid-offsetof -Wno-shadow -Wall -Wextra -Werror -Wno-unused-parameter -Wno-format-truncation -Wno-unused-variable -Wno-error=parentheses -Werror -MD -MT lib/swoc/unit_tests/CMakeFiles/test_libswoc.dir/test_TextView.cc.o -MF lib/swoc/unit_tests/CMakeFiles/test_libswoc.dir/test_TextView.cc.o.d -o lib/swoc/unit_tests/CMakeFiles/test_libswoc.dir/test_TextView.cc.o -c /home/jenkins/workspace/Github_Builds/autest/src/lib/swoc/unit_tests/test_TextView.cc
FAILED: lib/swoc/unit_tests/CMakeFiles/test_libswoc.dir/test_TextView.cc.o 
/usr/sbin/ccache /usr/sbin/c++ -DDEBUG -DOPENSSL_API_COMPAT=10002 -DOPENSSL_IS_OPENSSL3 -DPACKAGE_NAME="\"Apache Traffic Server\"" -DPACKAGE_VERSION=\"11.0.0\" -D_DEBUG -Dlinux -I/home/jenkins/workspace/Github_Builds/autest/src/include -I/home/jenkins/workspace/Github_Builds/autest/src/build/include -I/home/jenkins/workspace/Github_Builds/autest/src/lib/swoc/include -I/home/jenkins/workspace/Github_Builds/autest/src/lib/Catch2/src/catch2/.. -I/home/jenkins/workspace/Github_Builds/autest/src/build/lib/Catch2/generated-includes -pthread -g -std=c++17 -DENABLE_SYSTEMTAP_PROBES -Wno-invalid-offsetof -Wno-shadow -Wall -Wextra -Werror -Wno-unused-parameter -Wno-format-truncation -Wno-unused-variable -Wno-error=parentheses -Werror -MD -MT lib/swoc/unit_tests/CMakeFiles/test_libswoc.dir/test_TextView.cc.o -MF lib/swoc/unit_tests/CMakeFiles/test_libswoc.dir/test_TextView.cc.o.d -o lib/swoc/unit_tests/CMakeFiles/test_libswoc.dir/test_TextView.cc.o -c /home/jenkins/workspace/Github_Builds/autest/src/lib/swoc/unit_tests/test_TextView.cc
../lib/swoc/unit_tests/test_TextView.cc: In function 'void CATCH2_INTERNAL_TEST_0()':
../lib/swoc/unit_tests/test_TextView.cc:31:29: error: call of overloaded 'TextView(<brace-enclosed initializer list>)' is ambiguous
   31 |   TextView u{base.data(), ux};
      |                             ^
../lib/swoc/unit_tests/test_TextView.cc:31:29: note: there are 2 candidates
In file included from ../lib/swoc/unit_tests/test_TextView.cc:16:
../lib/swoc/include/swoc/TextView.h:1135:20: note: candidate 1: 'constexpr swoc::_1_5_15::TextView::TextView(const char*, int)'
 1135 |   inline constexpr TextView::TextView(const char *ptr, int n) noexcept
      |                    ^~~~~~~~
../lib/swoc/include/swoc/TextView.h:1131:20: note: candidate 2: 'constexpr swoc::_1_5_15::TextView::TextView(const char*, size_t)'
 1131 |   inline constexpr TextView::TextView(const char *ptr, size_t n) noexcept
      |                    ^~~~~~~~
[647/1599] /usr/sbin/ccache /usr/sbin/c++ -DDEBUG -DOPENSSL_API_COMPAT=10002 -DOPENSSL_IS_OPENSSL3 -DPACKAGE_NAME="\"Apache Traffic Server\"" -DPACKAGE_VERSION=\"11.0.0\" -D_DEBUG -Dlinux -Dtsapi_EXPORTS -I/home/jenkins/workspace/Github_Builds/autest/src/include -I/home/jenkins/workspace/Github_Builds/autest/src/build/include -I/home/jenkins/workspace/Github_Builds/autest/src/lib/swoc/include -I/home/jenkins/workspace/Github_Builds/autest/src/lib/yamlcpp/include -isystem /opt/openssl-quic/include -pthread -g -std=c++20 -fPIC -DENABLE_SYSTEMTAP_PROBES -Wno-invalid-offsetof -pipe -Wall -Wextra -Wno-noexcept-type -Wsuggest-override -Wno-vla-extension -fno-strict-aliasing -Wno-format-truncation -Werror -MD -MT src/api/CMakeFiles/tsapi.dir/InkAPITest.cc.o -MF src/api/CMakeFiles/tsapi.dir/InkAPITest.cc.o.d -o src/api/CMakeFiles/tsapi.dir/InkAPITest.cc.o -c /home/jenkins/workspace/Github_Builds/autest/src/src/api/InkAPITest.cc
[648/1599] /usr/sbin/ccache /usr/sbin/c++ -DDEBUG -DOPENSSL_API_COMPAT=10002 -DOPENSSL_IS_OPENSSL3 -DPACKAGE_NAME="\"Apache Traffic Server\"" -DPACKAGE_VERSION=\"11.0.0\" -D_DEBUG -Dlinux -I/home/jenkins/workspace/Github_Builds/autest/src/include -I/home/jenkins/workspace/Github_Builds/autest/src/build/include -I/home/jenkins/workspace/Github_Builds/autest/src/lib/swoc/include -I/home/jenkins/workspace/Github_Builds/autest/src/lib/Catch2/src/catch2/.. -I/home/jenkins/workspace/Github_Builds/autest/src/build/lib/Catch2/generated-includes -pthread -g -std=c++17 -DENABLE_SYSTEMTAP_PROBES -Wno-invalid-offsetof -Wno-shadow -Wall -Wextra -Werror -Wno-unused-parameter -Wno-format-truncation -Wno-unused-variable -Wno-error=parentheses -Werror -MD -MT lib/swoc/unit_tests/CMakeFiles/test_libswoc.dir/ex_bw_format.cc.o -MF lib/swoc/unit_tests/CMakeFiles/test_libswoc.dir/ex_bw_format.cc.o.d -o lib/swoc/unit_tests/CMakeFiles/test_libswoc.dir/ex_bw_format.cc.o -c /home/jenkins/workspace/Github_Builds/autest/src/lib/swoc/unit_tests/ex_bw_format.cc
ninja: build stopped: subcommand failed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants