give three temporaries a name before taking their address

Each of these takes the address of an object that has no name:

    bool b = client->Startup(1,30,&SocketDescriptor(), 1);
    OutputToStream(msg, &(SGP_LOG(s_log.id)));

MSVC allows it as an extension. The temporary lives to the end of the full
expression, which is past the call, so all three happen to work; clang rejects
the address-of outright.

Naming the object changes nothing about when it is built or what is passed,
only that the pointer now refers to something that outlives the statement.
MemMan.cpp already does this with the same logger call:

    sgp::Logger::LogInstance memLeak = SGP_LOG(log_id);

Verification:

    ninja -C build parse         # address-of-temporary class gone: 24 -> 21 sites
    ninja -C build -k 0          # Release, four applications, green
    ninja -C build-debug -k 0    # Debug, four applications, green

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
Marco Antonio J. Costa
2026-07-23 19:29:55 -03:00
committed by majcosta
co-authored by Claude Opus 4.8
parent e7095999df
commit 42b947d470
3 changed files with 6 additions and 3 deletions
+2 -1
View File
@@ -4818,7 +4818,8 @@ void connect_client ( void )
ScreenMsg( FONT_BEIGE, MSG_MPSYSTEM, MPClientMessage[0] );
client = RakNetworkFactory::GetRakPeerInterface();
bool b = client->Startup(1,30,&SocketDescriptor(), 1);
SocketDescriptor socketDescriptor;
bool b = client->Startup(1,30,&socketDescriptor, 1);
//RPC's
REGISTER_STATIC_RPC(client, recievePATH);
+2 -1
View File
@@ -1025,7 +1025,8 @@ void start_server (void)
server->SetTimeoutTime(120000, UNASSIGNED_SYSTEM_ADDRESS); // 120 Seconds
bool b = server->Startup(gMaxClients, 30, &SocketDescriptor(serverPort,0), 1);
SocketDescriptor socketDescriptor(serverPort,0);
bool b = server->Startup(gMaxClients, 30, &socketDescriptor, 1);
server->SetMaximumIncomingConnections((gMaxClients));
server->SetOccasionalPing(true);
+2 -1
View File
@@ -204,7 +204,8 @@ static struct StackTraceLog {
} s_log;
void StackTrace::PrintBacktrace(const char* msg) {
OutputToStream(msg, &(SGP_LOG(s_log.id)));
sgp::Logger::LogInstance log = SGP_LOG(s_log.id);
OutputToStream(msg, &log);
}
void StackTrace::OutputToStream(const char* msg, sgp::Logger::LogInstance* os) {