我一直在使用带有 g++ 4.7.2 的 CppUTest 一段时间,没有出现任何问题。但是,我刚刚打开了该-std=c++11
选项,因此我可以开始使用std::unique_ptr
它并立即失败。
即使只是编译主模块:
#include <CppUTest/CommandLineTestRunner.h>
int main(int argc, char ** argv) {
return CommandLineTestRunner::RunAllTests(argc, argv);
}
因以下变化而失败:
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)’
删除该-std=c++11
选项会使一切再次正常工作。
CppUTest 文档对与重载的新运算符冲突的宏进行了一些评论,并建议首先#include 标准头文件,但我在根本不包含任何头文件的情况下遇到了这个问题,尽管它看起来像是CppUTest/CommandLineTestRunner.h
包含了<string>
它自己。
有人遇到过这个问题或知道问题是什么吗?