grahamsedman opened a new pull request, #13187:
URL: https://github.com/apache/trafficserver/pull/13187
**Note:** This PR replaces #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`).
### 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:**
```text
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
* lib/swoc/include/swoc/TextView.h: Revised includes headers and removed
ambiguous constructor declarations and definitions.
* lib/swoc/include/swoc/TextView.cc: Revised includes headers to match
those used in the header file.
* Updated includes as requested.
* Formatting: Applied clang-format, yapf, and cmake-format to both files
to ensure code style compliance. (missing on PR #13185).
**Checklist:**
- [x] Code compiles on 32-bit ARM
- [x] Code compiles on 64-bit x86_64
- [x] Constructor logic preserved
- [x] Includes reorganized
- [x] Commits are GPG verified (missing on PR #13185)
### Compilation Errors Observed
/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
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]