On 28/08/2019 18.04, Rene Engelhard wrote:
[ Cc'ing the GCC maintainers ] Hi, On Tue, Aug 27, 2019 at 03:47:50PM +0200, Sorin Manolache wrote:When compiling a program with g++-9 (4:9.2.1-3) and linking with libcppunit then I get a segfault if the program uses std::stack.Hrmpf.For example: void f() { std::stack<std::string> s1; std::stack<unsigned int> s2; std::string str; CPPUNIT_ASSERT(r.empty()); // segfault here }That isn't a complete testcase? r doesn't exist (did you mean str?) or some of s1,s2 (empty stack)? Does it only happen if you CPPUNT_ASSERT it or also on "normal" std::stack usage? But I assume you file it here because it only happens with cppunit?
Sorry, I cannot reproduce the problem any more. Maybe I had some weird combination of g++ packages/libs on my system that some upgrade resolved.
Anyway, here is the real test case:
#include <stack>
#include <string>
#include <cppunit/TestAssert.h>
class X {
private:
std::stack<std::string> s1;
std::stack<unsigned int> s2;
};
int
main(int argc, char *argv[]) {
X *x = new X();
// delete x;
std::string r;
CPPUNIT_ASSERT(r.empty());
return 0;
}
Both valgrind and gdb reported that the problem was in the destructor
~Message, called by CPPUNIT_ASSERT. Message contains a
std::deque<std::string> and std::stack<T> is implemented by a std::deque<T>.
Anyway it was quite weird because it did not crash if I had just one stack in class X. I had to have two of them in order to have the crash.
std::stack alone, without cppunit, worked fine. Anyway, as said, I cannot reproduce it any more. Sorry for the false alarm. Best regards, Sorin