叮叮当当:什么可能导致NOLINT评论不被尊重?



我已经为开源流量服务器项目创建了一个 PR。他们运行叮叮当当作为他们CI的一部分。我的更改将一个新文件公开为 clang-tidy,该文件现在被标记为移动后使用警告。下面是测试代码,固定在我的更改所基于的提交处:

https://github.com/apache/trafficserver/blob/415cd8f/tests/tools/plugins/test_cppapi.cc#L115

这是该代码的副本,并添加了一条注释,显示了它抱怨的地方:

void
f()
{
TestCont::Mutex m(TSMutexCreate());
TestCont c(m);
ALWAYS_ASSERT(!!c)
ALWAYS_ASSERT(c.asTSCont() != nullptr)
ALWAYS_ASSERT(c.mutex() == m)
TestCont c2(std::move(c));
ALWAYS_ASSERT(!!c2)
ALWAYS_ASSERT(c2.asTSCont() != nullptr)   // <--- Complains here
ALWAYS_ASSERT(c2.mutex() == m)
ALWAYS_ASSERT(!c)
ALWAYS_ASSERT(c.asTSCont() == nullptr)
ALWAYS_ASSERT(c.mutex() == nullptr)

所以抱怨是有道理的,c2 是在移动后使用的。但在这种情况下,TestCont显式支持在设计移动后使用,并且测试有意执行此操作以确保其状态符合预期。

因此,这是一种NOLINTNOLINTNEXTLINE的情况。所以我应用了这样的评论(显然,出于绝望,我添加了比我应该需要的更多的评论(:

// NOLINTNEXTLINE
ALWAYS_ASSERT(!c) // NOLINT
// We turn off the clang-tidy warning about this being a use after move
// because that is the intention of the test. Continuations support use after
// move.
// NOLINTNEXTLINE
const auto cont_after_move = c.asTSCont(); // NOLINT
ALWAYS_ASSERT(cont_after_move == nullptr)
// We turn off the clang-tidy warning about this being a use after move
// because that is the intention of the test. Continuations support use after
// move.
// NOLINTNEXTLINE
const auto mutex_after_move = c.mutex(); // NOLINT
ALWAYS_ASSERT(mutex_after_move == nullptr)

请注意,我将c.asTSCont()作为单独的调用分开,以防ALWAYS_ASSERT宏混淆事情。然而,叮叮当当还是抱怨。以下是最新的 jenkins 运行输出:

https://ci.trafficserver.apache.org/job/clang-analyzer-github/12245/console

tools/plugins/test_cppapi.cc:124:32: warning: Method called on moved-from object 'c'
const auto cont_after_move = c.asTSCont(); // NOLINT
^~~~~~~~~~~~
tools/plugins/test_cppapi.cc:151:33: warning: Method called on moved-from object 'c2'
const auto cont2_after_move = c2.asTSCont(); // NOLINT
^~~~~~~~~~~~~
2 warnings generated.

警告输出中是NOLINT注释。我做错了什么?为什么叮叮当当的喘息不NOLINT

叮叮当当的版本是 10.0.0。这是 clang 分析器报告,以防它有帮助:

https://ci.trafficserver.apache.org/clang-analyzer/github/6945/2020-06-25-081635-12865-1/report-33708c.html#EndPath

下面是 clang-tidy 调用的复制和粘贴:

clang -cc1 -triple x86_64-unknown-linux-gnu -analyze -disable-free -disable-llvm-verifier -discard-value-names -main-file-name test_cppapi.cc -analyzer-store=region -analyzer-opt-analyze-nested-blocks -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=cplusplus -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -setup-static-analyzer -mrelocation-model pic -pic-level 2 -mthread-model posix -mframe-pointer=none -relaxed-aliasing -fmath-errno -fno-rounding-math -masm-verbose -mconstructor-aliases -munwind-tables -target-cpu x86-64 -target-feature +cx16 -dwarf-column-info -fno-split-dwarf-inlining -debugger-tuning=gdb -resource-dir /opt/llvm/lib64/clang/10.0.0 -D HAVE_CONFIG_H -I . -I ../include -D linux -D _LARGEFILE64_SOURCE=1 -D _COMPILE64BIT_SOURCE=1 -D _REENTRANT -D __STDC_LIMIT_MACROS=1 -D __STDC_FORMAT_MACROS=1 -I /var/jenkins/workspace/clang-analyzer-github/src/proxy/api -I /var/jenkins/workspace/clang-analyzer-github/src/proxy/api -I /var/jenkins/workspace/clang-analyzer-github/src/include/cppapi/include -I /var/jenkins/workspace/clang-analyzer-github/src/lib/cppapi/include -I /var/jenkins/workspace/clang-analyzer-github/src/include -I /var/jenkins/workspace/clang-analyzer-github/src/lib -D _GNU_SOURCE -D OPENSSL_NO_SSL_INTERN -I /opt/llvm/include/c++/v1 -D PIC -internal-isystem /opt/llvm/bin/../include/c++/v1 -internal-isystem /usr/local/include -internal-isystem /opt/llvm/lib64/clang/10.0.0/include -internal-externc-isystem /include -internal-externc-isystem /usr/include -O3 -Wno-deprecated-declarations -Wno-ignored-qualifiers -Wno-unused-parameter -Wno-invalid-offsetof -std=c++17 -fdeprecated-macro -fdebug-compilation-dir /var/jenkins/workspace/clang-analyzer-github/src/tests -ferror-limit 19 -fmessage-length 0 -fgnuc-version=4.2.1 -fobjc-runtime=gcc -fcxx-exceptions -fexceptions -fdiagnostics-show-option -vectorize-loops -vectorize-slp -analyzer-checker alpha.unix.cstring.BufferOverlap -analyzer-checker alpha.core.BoolAssignment -analyzer-checker alpha.core.CastSize -analyzer-checker alpha.core.SizeofPtr -analyzer-output=html -faddrsig -o /CA/clang-analyzer/github/6945/2020-06-25-081635-12865-1 -x c++ tools/plugins/test_cppapi.cc

最后,我在clang-tidy和clang-analyzer之间混淆了。NOLINT 解决了叮当声整洁的问题,但我不得不抑制叮当声分析器。我使用这里的建议这样做:

https://clang-analyzer.llvm.org/faq.html#exclude_code

以下指令为我平息了警告:

#ifndef __clang_analyzer__
// Code not to be analyzed
#endif

最新更新