Question

I've been using CppUTest with g++ 4.7.2 for a while now without problems. However, I've just flipped the -std=c++11 option on so I can start using std::unique_ptr and it fails immediately.

Even just compiling the main module:

#include <CppUTest/CommandLineTestRunner.h>

int main(int argc, char ** argv) {
    return CommandLineTestRunner::RunAllTests(argc, argv);
}

fails with variations on:

In file included from /usr/include/CppUTest/TestHarness.h:77:0,
                 from /usr/include/CppUTest/CommandLineTestRunner.h:31,
                 from tests/testmain.cpp:15:
/usr/include/CppUTest/MemoryLeakWarningPlugin.h:56:53: error: declaration of ‘void* operator new(size_t) throw (std::bad_alloc)’ has a different exception specifier
In file included from /usr/include/c++/4.7/ext/new_allocator.h:34:0,
                 from /usr/include/c++/4.7/x86_64-linux-gnu/bits/c++allocator.h:34,
                 from /usr/include/c++/4.7/bits/allocator.h:48,
                 from /usr/include/c++/4.7/string:43,
                 from /usr/include/CppUTest/SimpleString.h:136,
                 from /usr/include/CppUTest/Utest.h:34,
                 from /usr/include/CppUTest/TestHarness.h:71,
                 from /usr/include/CppUTest/CommandLineTestRunner.h:31,
                 from tests/testmain.cpp:15:
/usr/include/c++/4.7/new:93:7: error: from previous declaration ‘void* operator new(std::size_t)’

Removing the -std=c++11 option makes everything work just fine again.

The CppUTest documentation makes some comments about the macros conflicting with overloaded new operators, and suggests #including the standard headers first, but I get this problem without including any headers at all, although it looks like CppUTest/CommandLineTestRunner.h is including <string> itself.

Anyone come across this before or know what the issue is?

No correct solution

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top