Get the latest tech news

When can the C++ compiler devirtualize a call?


Someone recently asked me about devirtualization optimizations: when do they happen? when can we rely on devirtualization? do different compilers do devirtualization differently? As usual, this led me down an experimental rabbit-hole. The answer seems to be: Modern compilers devirtualize calls to final methods pretty reliably. But there are many interesting corner cases — including some I haven’t thought of, I’m sure! — and different compilers do catch different subsets of those corner cases.

None

Get the Android app

Or read this on Hacker News

Read more on:

Photo of C++

C++

Photo of C++ compiler

C++ compiler

Related news:

News photo

Making Julia as Fast as C++ (2019)

News photo

"Parse, don't validate" through the years with C++

News photo

C++: Freestanding Standard Library