andreasfertig / cppinsights

C++ Insights - See your source code with the eyes of a compiler
https://cppinsights.io
MIT License
4.04k stars 238 forks source link

Static casts missing with inherited classes #639

Open nevesnunes opened 4 months ago

nevesnunes commented 4 months ago

Not sure if this is one of the cases where non-compilable output is expected.

I came across this snippet where a class is defined with multiple inheritances, and then offsets of inherited objects are read after casting through all inheritance levels.

C++ Insights is only outputting the last class static_cast for each printf, so the first one will look like this:

printf("%c", static_cast<int>(static_cast<char>((reinterpret_cast<long *>(static_cast<A *>(&c)) - reinterpret_cast<long *>(&c)))));

g++ 12.2.0 error:

hello.cc:117:96: error: ‘main()::A’ is an ambiguous base of ‘main()::O’           
  117 | static_cast<char>((reinterpret_cast<long *>(static_cast<A *>(&c)) - reinter
pret_cast<long *>(&c)))));