Skip to content

PR Replacement #13185: 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: 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 computers 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
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.

1 participant