Skip to content

Fix 32-bit compilation errors in TextView.h by removing ambiguous constructor overloads and revised TextView.cc header includes#13185

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

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

Conversation

@grahamsedman
Copy link
Copy Markdown

This PR fixes build failures occurring on 32-bit architectures (specifically arm-linux-gnueabihf).

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

  • Updated lib/swoc/include/swoc/TextView.h:
    • Removed ambiguous constructor declarations.
    • Removed ambiguous constructor definitions.
    • Updated includes as requested.

Checklist:

  • Code compiles on 32-bit ARM
  • Code compiles on 64-bit x86_64
  • Constructor logic preserved
  • Update code formatting using clang format on both TextView.h and TextView.cc
  • Revised includes headers on the file TextView.cc to the ones used in the TextView.h header file

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.
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR addresses 32-bit (ILP32) build failures in SWOC’s TextView by removing constructor overloads that become duplicate signatures when size_t == unsigned and ssize_t == int (e.g., arm-linux-gnueabihf). It also aligns TextView.cc to rely on the headers included by TextView.h.

Changes:

  • Removed the TextView(char const *, unsigned) and TextView(char const *, ssize_t) constructor overloads, retaining only size_t and int forms to avoid 32-bit redeclaration errors.
  • Updated/expanded TextView.h standard library includes and adjusted TextView.cc includes accordingly.
  • Applied clang-format–driven formatting updates (notably namespace/brace layout).

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
lib/swoc/src/TextView.cc Drops redundant includes and relies on TextView.h for required standard headers; formatting updates only.
lib/swoc/include/swoc/TextView.h Removes ambiguous constructor overloads causing 32-bit signature collisions; updates includes and reformats inline implementations.

Comment on lines +1129 to +1130
// @internal If there is more than one overload for numeric types, it's easy to get ambiguity. The only
// fix, unfortunately, is lots of overloads to cover the ambiguous cases.
* is @c nullptr the length is 0. Otherwise @c strlen is used to calculate the length.
*/
constexpr TextView(char const *ptr, int n) noexcept;

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.

2 participants