2017-10-09 14 views
6

tldr;> clang-tidyのシステムヘッダーから警告を隠すにはどうすればよいですか?clang-tidyのシステムヘッダーを無視する

私はシステムヘッダで打ち鳴らす-きちんと警告をトリガし、次の最小限のサンプルソースファイル、持っている:

#include <future> 

int main() { 
    std::promise<int> p; 
    p.set_value(3); 
} 

は、Ubuntuの17.04で打ち鳴らす-きちんと4.0.0を使用してのlibstdC++ 7.0.1とそれを呼び出すに:

$ clang-tidy main.cpp -extra-arg=-std=c++14 

利回り

Running without flags. 
1 warning generated. 
/usr/lib/gcc/x86_64-linux-gnu/7.0.1/../../../../include/c++/7.0.1/mutex:693:5: warning: Address of stack memory associated with local variable '__callable' is still referred to by the global variable '__once_callable' upon returning to the caller. This will be a dangling reference [clang-analyzer-core.StackAddressEscape] 
    } 
    ^
/home/user/main.cpp:5:3: note: Calling 'promise::set_value' 
    p.set_value(3); 
^
/usr/lib/gcc/x86_64-linux-gnu/7.0.1/../../../../include/c++/7.0.1/future:1094:9: note: Calling '_State_baseV2::_M_set_result' 
     { _M_future->_M_set_result(_State::__setter(this, std::move(__r))); } 
     ^
/usr/lib/gcc/x86_64-linux-gnu/7.0.1/../../../../include/c++/7.0.1/future:401:2: note: Calling 'call_once' 
     call_once(_M_once, &_State_baseV2::_M_do_set, this, 
     ^
/usr/lib/gcc/x86_64-linux-gnu/7.0.1/../../../../include/c++/7.0.1/mutex:691:11: note: Assuming '__e' is 0 
     if (__e) 
     ^
/usr/lib/gcc/x86_64-linux-gnu/7.0.1/../../../../include/c++/7.0.1/mutex:691:7: note: Taking false branch 
     if (__e) 
    ^
/usr/lib/gcc/x86_64-linux-gnu/7.0.1/../../../../include/c++/7.0.1/mutex:693:5: note: Address of stack memory associated with local variable '__callable' is still referred to by the global variable '__once_callable' upon returning to the caller. This will be a dangling reference 
    } 

私は警告非表示にしたいですシステムヘッダーに含まれています。私は以下を試した:

$ clang-tidy -extra-arg=-std=c++14 main.cpp -header-filter=$(realpath .) -system-headers=0 

しかし、まだ警告が表示されます。

答えて

2

私もこの問題に遭遇しましたが、それを理解しようとしばらく時間を費やしましたが、このタイプの警告をclang-tidyで無効にする方法はありませんでした。

this discussion on the LLVM issue tracker regarding a similar issueを読んでから、私はこの問題は、set_valueへの呼び出しがあるからであるための打ち鳴らす-整頓観点から、警告が実際に、main.cppに位置していることであるという印象を受けます。

私の回避策は、clang-tidyで静的解析チェックを無効にし、scan-build utilityを使用してclangの静的解析を実行することです。これはこれらの問題を回避するようです。たとえば、あなたのmain.cppを使用して:

$ scan-build-3.9 clang++ -std=c++14 main.cpp 
scan-build: Using '/usr/lib/llvm-3.9/bin/clang' for static analysis 
In file included from main.cpp:1: 
In file included from /usr/lib/gcc/x86_64-linux-gnu/6.3.0/../../../../include/c++/6.3.0/future:39: 
/usr/lib/gcc/x86_64-linux-gnu/6.3.0/../../../../include/c++/6.3.0/mutex:621:11: warning: Address of stack memory associated with local variable '__callable' is still referred to by the global variable '__once_callable' upon returning to the caller. This will be a dangling reference 
     if (__e) 
      ^~~ 
1 warning generated. 
scan-build: Removing directory '/tmp/scan-build-2017-12-02-112018-13035-1' because it contains no reports. 
scan-build: No bugs found. 

アナライザは、システムヘッダ内の同じ誤りを発見し、それが最終報告書に含めるしないように十分にスマートです。

スタイルガイドタイプの警告(modernize-*またはreadability-*など)に興味がある場合は、引き続きclang-tidyを別途実行する必要があります。

関連する問題