grahamsedman opened a new pull request, #13185:
URL: https://github.com/apache/trafficserver/pull/13185
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
* Updated `lib/swoc/include/swoc/TextView.h`:
* Removed ambiguous constructor declarations.
* Removed ambiguous constructor definitions.
* Updated includes as requested.
**Checklist:**
- [x] Code compiles on 32-bit ARM
- [x] Code compiles on 64-bit x86_64
- [x] Constructor logic preserved
- [x] Update code formatting using clang format on both `TextView.h` and
`TextView.cc`
- [x] 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
--
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]