https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114388
Bug ID: 114388
Summary: Behavioral change of typeid on xvalues since GCC 9
Product: gcc
Version: 9.5.0
Status: UNCONFIRMED
Keywords: wrong-code
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: de34 at live dot cn
Target Milestone: ---
IIUC this program behaves differently in C++98 and C++11 due to WG21 N3055
(https://wg21.link/n3055):
```
#include <typeinfo>
#include <cstdio>
struct B {
virtual ~B() { std::puts("~B"); }
};
struct D : B {};
struct WrapB {
B b;
};
struct WrapD {
D d;
};
int main() {
typeid(true ? WrapB().b : WrapD().d);
}
```
Before C++11/N3055, the operand of the typeid expression shouldn't be evaluated
because it's a rvalue. But since C++11 it should be evaluated because it's a
glvalue of a polymorphic class type.
It's curious that GCC behaves consistently on this in C++98 and C++11 modes.
Per https://godbolt.org/z/7oGdjdMK7, it seems that GCC 8 (and former versions)
applied the C++98 rules to C++11 and later modes, and GCC 9 (and later verions)
applied the C++11 rules to C++98 mode.
For later versions, I'm not sure whether this is a bug (in C++98 mode) or an
intentional backporting.