2009-02-08 5 views
29

나는 새 프로젝트를 시작했으며/Wall 옵션을 활성화 한 상태로 완전히 빌드되었는지 확인하기로 결정했습니다. 유일한 문제는 경고없이 컴파일 (부스트 등) 모든 제 3 자 라이브러리없는, 그래서 공유 헤더이 일에 의지 한이 충분히 잘 작동플러그 - 마를 사용하여 모든 경고를 비활성화하는 방법이 있습니까?

#pragma warning(push) 

#pragma warning(disable:4820) 
#pragma warning(disable:4619) 
#pragma warning(disable:4668) 
#pragma warning(disable:4625) 
#pragma warning(disable:4626) 
#pragma warning(disable:4571) 
#pragma warning(disable:4347) 
#pragma warning(disable:4640) 
#pragma warning(disable:4365) 
#pragma warning(disable:4710) 
#pragma warning(disable:4820) 
#pragma warning(disable:4350) 
#pragma warning(disable:4686) 
#pragma warning(disable:4711) 
#pragma warning(disable:4548) 

#include <boost/array.hpp> 
#include <boost/assert.hpp> 
#include <boost/assign.hpp> 
#include <boost/bind.hpp> 
#include <boost/lexical_cast.hpp> 
#include <boost/filesystem.hpp> 
#include <boost/foreach.hpp> 
#include <boost/format.hpp> 
#include <boost/function.hpp> 
#include <boost/integer.hpp> 
#include <boost/optional.hpp> 
#include <boost/regex.hpp> 
#include <boost/smart_ptr.hpp> 
#include <boost/algorithm/string.hpp> 
#include <boost/tuple/tuple.hpp> 
#include <boost/utility.hpp> 
#include <boost/variant.hpp> 

#pragma warning(pop) 

하지만 때마다 나는 새로운 부스트 헤더를 추가 그들이 생성하는 경고를 목록에 추가해야합니다. 이 코드 스트레치에 대해 모든 경고를 해제하는 방법이 있습니까?

#pragma warning(push, 0)   

#include <boost/bind.hpp> 
#include <boost/shared_ptr.hpp> 
// ... 

#pragma warning(pop) 

을하지만 모든 경고를 비활성화 할 수 없습니다 것을 알고 :

답변

40
당신은 밀 수

는/다음과 같이 경고의 낮은 수준을 나타. 예를 들어 일부 링커 경고는 해제 할 수 없습니다. 나는 모든 "#INCLUDE 후에 상단에

#pragma warning(push, 4) 

을 넣어 내가 내 자신의 소스의 .cpp 파일의 각 다음"벽 "보다는"W3 "옵션을 설정하기 전에했던

+0

여기에서 나는 경고의 푸시/팝과 1 대 1 관계를 참조하십시오. N 개의 경고를 비활성화하면 N 번 팝해야합니다. 다시 말하지만, 오래된 스레드를 유감스럽게 생각합니다. – wheaties

+2

해제하는 경고의 수는 부적합합니다. '푸시'의 수는 모두 '팝'의 수와 일치해야합니다. –

+2

또한,'#pragma warning (pop)'을 사용하면 일부 경고 (4514가 예임)가 여전히 발행된다는 사실이 흥미 롭습니다. 아마도 이러한 경고 조건이 일부 컴파일 후 컨텍스트에서 감지 되었기 때문일 수 있습니다. – alecov

4

... "줄을 입력 한 다음

#pragma warning(pop) 

을 파일의 마지막 줄로 사용하십시오.

이 방법을 사용하면 코드에서 레벨 4 경고를 얻을 수 있고 제 3 자 코드에서 레벨 3을 얻을 수 있습니다.

적은 라인
+1

문제가되는 제 3의'#include '를 감싸는 것보다 자신의 모든 코드 파일을'#pragma warning' 지시어로 감싸는 것이 더 많은 일로 보입니다. 하지만 네가 잘하면 ... –

17
#pragma warning(disable:4820) 
#pragma warning(disable:4619) 
#pragma warning(disable:4668) 

.... 내가 강령술하지만 귀하의 코멘트에 용납 할 의미하지 않는다

#pragma warning (disable : 4820 4619 4668) 
관련 문제