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]

# 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]