Skip to content

Commit 30ea751

Browse files
committed
Fix StringLiteral operator+() for characters
1 parent 69acfa9 commit 30ea751

File tree

2 files changed

+16
-12
lines changed

2 files changed

+16
-12
lines changed

lib/utility/include/qx/utility/qx-stringliteral.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ constexpr auto operator+(const typename S::data_t (&a)[N1], const S& b) { return
160160
* Returns a string which is the result of concatenating @a a and @a b.
161161
*/
162162
template<string_literal S>
163-
constexpr auto operator+(const S& a, typename S::data_t b) { return operator+(a, {b}); }
163+
constexpr auto operator+(const S& a, typename S::data_t b) { return operator+(a, {b, '\0'}); }
164164

165165
// Doc'ed here cause doxygen is finicky
166166
/*!
@@ -169,7 +169,7 @@ constexpr auto operator+(const S& a, typename S::data_t b) { return operator+(a,
169169
* Returns a string which is the result of concatenating @a a and @a b.
170170
*/
171171
template<string_literal S>
172-
constexpr auto operator+(typename S::data_t a, const S& b) { return operator+({a}, b); }
172+
constexpr auto operator+(typename S::data_t a, const S& b) { return operator+({a, '\0'}, b); }
173173

174174
/* TOOO: We use derivations here instead of template aliases as parameter deduction for aliases
175175
* (what allows the parameter to deduce the character type and size just based on the

lib/utility/src/qx-stringliteral.dox

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@ namespace Qx
5151
* @fn StringLiteral::StringLiteral(const C (&str)[N])
5252
*
5353
* Wraps the raw string @a str of length @a N.
54+
*
55+
* @warning If preparing a character array manually, be sure to included a null-terminator as its presence
56+
* is assumed! If none is provided, the "size" members will report incorrect values and concatenation will
57+
* result in UB.
5458
*/
5559

5660
//-Instance Functions----------------------------------------------------------------------------------------------------
@@ -149,9 +153,9 @@ namespace Qx
149153
//-Constructor-------------------------------------------------------------------------------------------------
150154
//Public:
151155
/*!
152-
* @fn CStringLiteral::CStringLiteral(const char (&str)[N])
156+
* @fn CStringLiteral::CStringLiteral(const char (&str)[N])
153157
*
154-
* Wraps the raw string @a str of length @a N.
158+
* @copydoc StringLiteral::StringLiteral(const C (&str)[N])
155159
*/
156160

157161
//===============================================================================================================
@@ -168,9 +172,9 @@ namespace Qx
168172
//-Constructor-------------------------------------------------------------------------------------------------
169173
//Public:
170174
/*!
171-
* @fn WStringLiteral::WStringLiteral(const wchar_t (&str)[N])
175+
* @fn WStringLiteral::WStringLiteral(const wchar_t (&str)[N])
172176
*
173-
* Wraps the raw string @a str of length @a N.
177+
* @copydoc StringLiteral::StringLiteral(const C (&str)[N])
174178
*/
175179

176180
//===============================================================================================================
@@ -187,9 +191,9 @@ namespace Qx
187191
//-Constructor-------------------------------------------------------------------------------------------------
188192
//Public:
189193
/*!
190-
* @fn U8StringLiteral::U8StringLiteral(const char8_t (&str)[N])
194+
* @fn U8StringLiteral::U8StringLiteral(const char8_t (&str)[N])
191195
*
192-
* Wraps the raw string @a str of length @a N.
196+
* @copydoc StringLiteral::StringLiteral(const C (&str)[N])
193197
*/
194198

195199
//===============================================================================================================
@@ -206,9 +210,9 @@ namespace Qx
206210
//-Constructor-------------------------------------------------------------------------------------------------
207211
//Public:
208212
/*!
209-
* @fn U16StringLiteral::U16StringLiteral(const char16_t (&str)[N])
213+
* @fn U16StringLiteral::U16StringLiteral(const char16_t (&str)[N])
210214
*
211-
* Wraps the raw string @a str of length @a N.
215+
* @copydoc StringLiteral::StringLiteral(const C (&str)[N])
212216
*/
213217

214218
//===============================================================================================================
@@ -225,8 +229,8 @@ namespace Qx
225229
//-Constructor-------------------------------------------------------------------------------------------------
226230
//Public:
227231
/*!
228-
* @fn U32StringLiteral::U32StringLiteral(const char32_t (&str)[N])
232+
* @fn U32StringLiteral::U32StringLiteral(const char32_t (&str)[N])
229233
*
230-
* Wraps the raw string @a str of length @a N.
234+
* @copydoc StringLiteral::StringLiteral(const C (&str)[N])
231235
*/
232236
}

0 commit comments

Comments
 (0)