https://gcc.gnu.org/bugzilla/show_bug.cgi?id=89937
Bug ID: 89937 Summary: For example code, which is valid as either C or C++, optimization seems much better for C Product: gcc Version: unknown Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: wkaras at yahoo dot com Target Milestone: --- I compiled this code with -O2, and with either -x c or -x c++ . The optimization seems to work much better for C than for C++. typedef struct TSFastDbgCntl_ { const char * const tag; // nul-terminated string const char * const on; // pointer to 1-byte flag } TSFastDbgCntl; TSFastDbgCntl * TSCreateFastDbgCntl(const char *tag); #include <stdarg.h> void TSVDebug(const char *tag, const char *fmt, va_list args); inline void TSFastDbg(TSFastDbgCntl *fd_cntl, const char *fmt, ...) { if (fd_cntl->on) { va_list ap; va_start(ap, fmt); TSVDebug(fd_cntl->tag, fmt, ap); } } void dummy(int i, double d) { TSFastDbgCntl *fd_cntl = TSCreateFastDbgCntl("pluggymcplugin"); TSFastDbg(fd_cntl, "Test %d %f", i * 5, d * 7); TSFastDbg(fd_cntl, "Test fixed string"); } https://godbolt.org/z/d2MzPo Note that the difference in optimization of this code for C vs. C++ is similar for clang/LLVM.