2017-10-09 5 views
6

tldr>> 어떻게 시스템 헤더에서 경고를 숨길 수 있습니까?clang-tidy에서 시스템 헤더 무시

나는 시스템 헤더에 그 소리-깔끔한 경고를 트리거 다음과 같은 최소한의 예제 소스 파일이 있습니다

#include <future> 

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

우분투 17.04에 그 소리-깔끔한 4.0.0 사용 7.0.1 ++ 된 libstdc로 호출을 :

$ 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

나는이 문제에 대해서도 만났고 그걸 알아 내려고 노력했지만 시간이지나면서 이런 유형의 경고를 비활성화하는 방법을 발견 할 수 없었습니다. this discussion on the LLVM issue tracker regarding a similar issue 읽기에서

, 나는 문제가 set_value에 대한 호출이 거기에서 있기 때문에의 연타 - 깔끔한 관점에서, 경고가 실제로 main.cpp에 있는지 있다는 인상을받을.

제 해결 방법은 clang-tidy에서 정적 분석 검사를 비활성화하고 scan-build utility을 사용하여 clang의 정적 분석을 실행하는 것입니다. 이러한 분석은 이러한 문제를 피하는 것 같습니다.

$ 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. 

분석기는 시스템 헤더 같은 오류를 발견하지만, 최종 보고서에 포함하지 않을 정도로 똑똑 : 예를 들어, main.cpp를 사용. ("버그를 찾을 수 없습니다")

스타일 가이드 유형 경고 (예 : modernize-* 또는 readability-*)에 관심이있는 경우에도 clang-tidy를 별도로 실행해야합니다.

관련 문제