Donate. I desperately need donations to survive due to my health

Get paid by answering surveys Click here

Click here to donate

Remote/Work from Home jobs

c++ google tests segfault when comparing int from deque

update: as mentioned in another post, gtests may drop to the debugger if a test fails : Why is Google Test segfaulting? This is what seems to be happening here, as updating the code to comparing any two different integer values result in a segmentation fault. This is confusing, because other tests from the same test case (and therefore compiled and run at the same time) mark their test as not passing without segfault. I do not know what explains the difference of behavior between tests.

Here a snippet of code :

  // ...      

  std::deque<int> removed_ids;

  // write 2 values in removed_ids
  stack.remove(2,removed_ids);

  ASSERT_EQ(removed_ids.size(),2);

  int foo = 3;

  // this is printed, and values make sense, e.g. foo is 3
  std::cout << "IN | " << removed_ids.back()<< " | " << foo << "\n";

  ASSERT_EQ(removed_ids.back(),foo);

  // segmentation fault, never printed
  std::cout << "OUT\n";

Running the tests always lead to a segmentation fault at the second ASSERT (the one comparing removed_ids.back() and foo) ; i.e. "OUT" is not printed in the terminal ("IN" is, followed by values of int that makes sense).

This is in a file running other tests, also doing some asserts, all working fine.

I am very confused of what may be happening.

I am on Ubuntu 16.04, c++11

The tests are not run in a debugger (simple 'catkin_make run_tests')

Comments