我正在使用编译器资源管理器,在使用类似这样的东西时,我偶然发现了三元运算符的一个有趣行为:
std::string get_string(bool b)
{
return b ? "Hello" : "Stack-overflow";
}
Run Code Online (Sandbox Code Playgroud)
编译器为此生成的代码(clang trunk,带 -O3)是这样的:
get_string[abi:cxx11](bool): # @get_string[abi:cxx11](bool)
push r15
push r14
push rbx
mov rbx, rdi
mov ecx, offset .L.str
mov eax, offset .L.str.1
test esi, esi
cmovne rax, rcx
add rdi, 16 #< Why is the compiler storing the length of the string
mov qword ptr [rbx], rdi
xor sil, 1
movzx ecx, sil
lea r15, [rcx + 8*rcx]
lea r14, [rcx + 8*rcx]
add r14, 5 #< …Run Code Online (Sandbox Code Playgroud) 我是第一次使用 clang-tidy。我正在使用 OpenCV 完成我的论文。我的问题是,当我将 clang-tidy 配置为“修复”它发现的问题时,它也会修复它在 OpenCV 库中发现的问题。我的问题是:如何才能使 clang-tidy 只修复它在我创建的文件中发现的问题?