public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/114388] New: Behavioral change of typeid on xvalues since GCC 9
@ 2024-03-19  6:27 de34 at live dot cn
  2024-03-19  6:34 ` [Bug c++/114388] " de34 at live dot cn
                   ` (9 more replies)
  0 siblings, 10 replies; 11+ messages in thread
From: de34 at live dot cn @ 2024-03-19  6:27 UTC (permalink / raw)
  To: gcc-bugs

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.

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2024-04-30  6:53 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-03-19  6:27 [Bug c++/114388] New: Behavioral change of typeid on xvalues since GCC 9 de34 at live dot cn
2024-03-19  6:34 ` [Bug c++/114388] " de34 at live dot cn
2024-03-19  8:00 ` rguenth at gcc dot gnu.org
2024-03-19  8:21 ` de34 at live dot cn
2024-03-19 10:54 ` redi at gcc dot gnu.org
2024-03-19 11:12 ` redi at gcc dot gnu.org
2024-03-19 11:31 ` redi at gcc dot gnu.org
2024-03-19 11:43 ` de34 at live dot cn
2024-03-19 11:51 ` redi at gcc dot gnu.org
2024-03-19 11:54 ` redi at gcc dot gnu.org
2024-04-30  6:53 ` de34 at live dot cn

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).