This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c++/67576] New: expression of typeid( expression ) is evaluated twice


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67576

            Bug ID: 67576
           Summary: expression of typeid( expression ) is evaluated twice
           Product: gcc
           Version: 6.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: cctsai57 at gmail dot com
  Target Milestone: ---

#include <typeinfo>

struct Base { virtual void foo() {} }; // polymorphic

int main()
{
  Base b;
  Base *ary[] = { &b, &b, &b};

  int iter = 0;
  typeid(*ary[iter++]);
  if (iter != 1)        // should be 1
    __builtin_abort();  // but 2

  return iter;
}


Compiler version:4.9.x, 5.x, 6.0

Description:
The above simplified code would get a wrong `iter' value after typeid
statement.
It seems to evaluate `iter++' twice.

I found that the code has not worked since the following fix:

commit cdb704aa83247f82d7b9aae934639a6be2e6681b
Author: jason <jason@138bc75d-0d04-0410-961f-82ee72b054a4>
Date:   Tue Apr 9 18:11:38 2013 +0000

        PR c++/25466
        * rtti.c (build_typeid): Check the address of the argument
        rather than looking for an INDIRECT_REF.

    git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@197644
138bc75d-0d04-0410-961f-82ee72b054a4


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]