SIGSEGV within ternary operator when used std::string, Sun C++ 5.8 2005/10/

Hi,

I found that this simple program is crashing regularly:

[code]//

#include <string>

using namespace std;

typedef string A;

A fn() { return (0 ? A()+A() : A()+A()); }

int main() { fn(); }

//

[/code]

If I replace string by some other class, e.g. my own that implements

default and copy constructor and operator+(A&) then it works fine.

Probably it has connection with bugs 4225549, 6253074.

'CC -V' produces 'Sun C++ 5.8 2005/10/13'

[532 byte] By [mb78] at [2007-11-26 11:27:12]
# 1
The crash could be due to any of several known bugs that have been fixed. I cannot duplicate your problem using the latest patched version of Sun Studio 11.Make sure you have the latest patches for Studio 11, and the latest C++ runtime library patch.
clamage45 at 2007-7-7 3:42:52 > top of Java-index,Development Tools,Solaris and Linux Development Tools...
# 2
I saw similar problems about a year back or so (using Qt's QString, but the problem was probably similar). I haven't seen any problems for many months, when all patches are installed.Paul
Paul_Floyd at 2007-7-7 3:42:52 > top of Java-index,Development Tools,Solaris and Linux Development Tools...
# 3
I tried the sample program using C++ 5.8 with current patches applied, and the program ran without problems.
clamage45 at 2007-7-7 3:42:52 > top of Java-index,Development Tools,Solaris and Linux Development Tools...
# 4

We've seen this problem as well and reduced it to a small test case (see below).

It appears that the problem was fixed in Patch 121017-01 2005/12/11 (the the

output at the bottom of the post).

$ cat t.cpp && CC -V t.cpp && ./a.out

#include <stdio.h>

int n;

struct S {

int i;

S (): i (n++) { printf ("S::S() [%d]\n", i); }

S (const S &s): i (n++) { printf ("S::S(const S& [%d]) [%d]\n", s.i, i); }

~S () { printf ("S::~S() [%d]\n", i); }

};

inline S operator+ (const S &a, const S &b) {

printf ("operator+(const S& [%d], const S& [%d])\n", a.i, b.i);

return a;

}

S foo () { return 0 ? S () + S () : S () + S (); }

int main ()

{

foo ();

}

CC: Sun C++ 5.8 2005/10/13

/amd/packages/mdx/solaris/SUNWspro/C++5.8/prod/bin/c++filt: Sun C++ 5.8 2005/10/13

ccfe: Sun C++ 5.8 2005/10/13

ld: Software Generation Utilities - Solaris Link Editors: 5.10-1.480

S::S() [0]

S::S() [1]

operator+(const S& [0], const S& [1])

S::S(const S& [0]) [2]

S::S(const S& [3]) [3]

S::~S() [1]

S::~S() [0]

S::~S() [3]

$ CC -V t.cpp && ./a.out

CC: Sun C++ 5.8 Patch 121017-01 2005/12/11

/amd/packages/mdx/solaris/SUNWspro/C++5.8j1/prod/bin/c++filt: Sun C++ 5.8 2005/10/13

ccfe: Sun C++ 5.8 Patch 121017-01 2005/12/11

ld: Software Generation Utilities - Solaris Link Editors: 5.10-1.480

S::S() [0]

S::S() [1]

operator+(const S& [0], const S& [1])

S::S(const S& [0]) [2]

S::~S() [1]

S::~S() [0]

S::~S() [2]

sebor@roguewavecom at 2007-7-7 3:42:52 > top of Java-index,Development Tools,Solaris and Linux Development Tools...
# 5
Thank you very much,I tried the code and the result is the same as written for compiler without 121017-01 2005/12/11 patch.
mb78 at 2007-7-7 3:42:52 > top of Java-index,Development Tools,Solaris and Linux Development Tools...