Skip to content

Commit da60b25

Browse files
committed
Disable operator<<() for signed/unsigned char, to catch potential type
alias issues with bad int8_t definitions.
1 parent 37139f4 commit da60b25

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

include/st_stringstream.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,16 @@ namespace ST
197197
return append_char(ch);
198198
}
199199

200+
// Some systems alias int8_t as char rather than signed char.
201+
// We don't want to remove the char overload since it's often better
202+
// than streaming a string or calling .append_char(), so instead we
203+
// can disable the use of these overloads on "sane" platforms to
204+
// try to catch their misuse.
205+
// HINT: If you need to stream an int8_t or uint8_t, cast it to
206+
// an int or unsigned int to get the correct behavior...
207+
string_stream &operator<<(signed char) = delete;
208+
string_stream &operator<<(unsigned char) = delete;
209+
200210
string_stream &operator<<(const string &text)
201211
{
202212
return append(text.c_str(), text.size());

0 commit comments

Comments
 (0)