Skip to content

Commit 103e3f5

Browse files
authored
Make codegen better behaved on msvc / gcc
For some reason gcc assumes that static constexpr array can be modified and does not attempt to zero init the string, reading from the array instead. Having the buffer be initialized in the function instead via a consteval seems to yield proper results. MSVC just straight up doesn't understand static initialization and attempts to initialize the static buffer on every function call. Microsoft never fails to disappoint.
1 parent e00a702 commit 103e3f5

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

trantor/net/InetAddress.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,10 +206,10 @@ static void byteToChars(std::string::iterator& dst, unsigned char byte)
206206
++dst;
207207
}
208208

209-
static constexpr char stringInitBuffer[15]{};
210209
static std::string iptos(unsigned inet_addr)
211210
{
212211
// Initialize with a static buffer to force the constructor of string to get fully inlined
212+
constexpr char stringInitBuffer[15]{};
213213
std::string out(stringInitBuffer, 15);
214214
std::string::iterator dst = out.begin();
215215
byteToChars(dst, inet_addr >> 0 & 0xff);

0 commit comments

Comments
 (0)