我正在将当前使用gcc编译的项目移动到clang,并且有一堆gcc没有生成的警告(-Winconsistent-missing-override
).clang-tidy
用于修复*.cpp
文件中的这些错误,但它不会触及hpp
文件,因为在数据库中找不到编译命令(正如我所料).
我正在使用ninja
构建项目并ninja -t compdb cc cxx > .build/compile_commands.json
生成编译数据库.我试过跑:
clang-tidy-3.6 -p .build/ \
$(find src/ -name *.cpp) \
$(find src/ -name *.hpp) \
--checks=misc-use-override --fix
Run Code Online (Sandbox Code Playgroud)
修复错误.它拒绝触摸头文件抱怨:
Skipping .../src/header/file.hpp. Compile command not found.
Run Code Online (Sandbox Code Playgroud) 当尝试执行BOOST_CHECK_EQUAL(对,对)时,gcc没有找到对的流操作符,尽管声明它.有趣的是std :: out找到了运营商.
ostream& operator<<(ostream& s, const pair<int,int>& p) {
s << '<' << p.first << ',' << p.second << '>';
return s;
}
BOOST_AUTO_TEST_CASE(works)
{
pair<int,int> expected(5, 5);
pair<int,int> actual (5, 5);
std::cout << expected << std::endl;
std::cout << actual << std::endl;
BOOST_CHECK(actual == expected);
}
BOOST_AUTO_TEST_CASE(no_work)
{
pair<int,int> expected(5, 5);
pair<int,int> actual (5, 5);
BOOST_CHECK_EQUAL(actual, expected);
}
Run Code Online (Sandbox Code Playgroud)
这不会编译错误:
... instantiated from here
../boost-atp/release/include/boost/test/test_tools.hpp:326:9: error: no match for ‘operator<<’ in ‘ostr << t’
Run Code Online (Sandbox Code Playgroud) 即使它的签名说它应该,f()也不会返回.为什么允许这个编译?C标准是否有理由不要求编译器使其失败?
我知道它是未定义的行为和所有,但为什么它首先被允许?有历史原因吗?
double f(){}
int main()
{
f();
return 0;
}
Run Code Online (Sandbox Code Playgroud)