https://gcc.gnu.org/bugzilla/show_bug.cgi?id=79349
AK <hiraditya at msn dot com> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|NEW |RESOLVED Resolution|--- |WORKSFORME --- Comment #2 from AK <hiraditya at msn dot com> --- The problem is exceptions. When I compile without exceptions (-fno-exceptions) g++ does optimize this away and gives same output as clang. It seems clang++ compiles without exceptions by default and behaves like g++ when -fexceptions is passed.