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]

c++/1833: inlining sometimes causes incorrect behavior



>Number:         1833
>Category:       c++
>Synopsis:       inlining sometimes causes incorrect behavior
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Thu Feb 01 11:26:00 PST 2001
>Closed-Date:
>Last-Modified:
>Originator:     Peter Bartlett
>Release:        gcc version 2.95.2 19991024 (release)
>Organization:
>Environment:

>Description:
The attached program calls two versions of a function,
one inlined and the other not. The inlined function does
not behave correctly. The type casting of a (char *)
argument to (const char *) as an argument to another funtion
that takes (const char *&) does not properly modify the
argument in the calling function in the inlined version.
>How-To-Repeat:
#include <iostream>


void frob2 (const char*& s)
{
  s += 3;
}


inline void frob_fail (char *s)
{
  frob2((const char *)s);

  cerr << "should be 34567: " << s << endl;
}


void frob_pass (char *s)
{
  frob2((const char *)s);

  cerr << "should be 34567: " << s << endl;
}


int main (unsigned argc, const char *const argv[])
{
  char *x = "01234567";
  frob_fail(x);

  char *y = "01234567";
  frob_pass(y);
}
>Fix:

>Release-Note:
>Audit-Trail:
>Unformatted:

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