File tree Expand file tree Collapse file tree 3 files changed +42
-4
lines changed
Expand file tree Collapse file tree 3 files changed +42
-4
lines changed Original file line number Diff line number Diff line change @@ -1997,9 +1997,21 @@ impl Build {
19971997 // CFLAGS/CXXFLAGS, since those variables presumably already contain
19981998 // the desired set of warnings flags.
19991999 let envflags = self . envflags ( if self . cpp { "CXXFLAGS" } else { "CFLAGS" } ) ?;
2000- if self . warnings . unwrap_or ( envflags. is_none ( ) ) {
2001- let wflags = cmd. family . warnings_flags ( ) . into ( ) ;
2002- cmd. push_cc_arg ( wflags) ;
2000+ match self . warnings {
2001+ Some ( true ) => {
2002+ let wflags = cmd. family . warnings_flags ( ) . into ( ) ;
2003+ cmd. push_cc_arg ( wflags) ;
2004+ }
2005+ Some ( false ) => {
2006+ let wflags = cmd. family . warnings_suppression_flags ( ) . into ( ) ;
2007+ cmd. push_cc_arg ( wflags) ;
2008+ }
2009+ None => {
2010+ if envflags. is_none ( ) {
2011+ let wflags = cmd. family . warnings_flags ( ) . into ( ) ;
2012+ cmd. push_cc_arg ( wflags) ;
2013+ }
2014+ }
20032015 }
20042016 if self . extra_warnings . unwrap_or ( envflags. is_none ( ) ) {
20052017 if let Some ( wflags) = cmd. family . extra_warnings_flags ( ) {
Original file line number Diff line number Diff line change @@ -566,6 +566,13 @@ impl ToolFamily {
566566 }
567567 }
568568
569+ pub ( crate ) fn warnings_suppression_flags ( & self ) -> & ' static str {
570+ match * self {
571+ ToolFamily :: Msvc { .. } => "-W0" ,
572+ ToolFamily :: Gnu | ToolFamily :: Clang { .. } => "-w" ,
573+ }
574+ }
575+
569576 /// What the flags to enable extra warnings
570577 pub ( crate ) fn extra_warnings_flags ( & self ) -> Option < & ' static str > {
571578 match * self {
Original file line number Diff line number Diff line change @@ -173,6 +173,14 @@ fn gnu_warnings() {
173173 test. cmd ( 0 ) . must_have ( "-Wall" ) . must_have ( "-Wextra" ) ;
174174}
175175
176+ #[ test]
177+ fn gnu_warnings_disabled ( ) {
178+ let test = Test :: gnu ( ) ;
179+ test. gcc ( ) . warnings ( false ) . file ( "foo.c" ) . compile ( "foo" ) ;
180+
181+ test. cmd ( 0 ) . must_have ( "-w" ) . must_not_have ( "-Wall" ) ;
182+ }
183+
176184#[ test]
177185fn gnu_extra_warnings0 ( ) {
178186 reset_env ( ) ;
@@ -200,7 +208,10 @@ fn gnu_extra_warnings1() {
200208 . file ( "foo.c" )
201209 . compile ( "foo" ) ;
202210
203- test. cmd ( 0 ) . must_not_have ( "-Wall" ) . must_have ( "-Wextra" ) ;
211+ test. cmd ( 0 )
212+ . must_have ( "-w" )
213+ . must_not_have ( "-Wall" )
214+ . must_have ( "-Wextra" ) ;
204215}
205216
206217#[ test]
@@ -533,6 +544,14 @@ fn msvc_std_c() {
533544 test. cmd ( 0 ) . must_have ( "-std:c11" ) ;
534545}
535546
547+ #[ test]
548+ fn msvc_warnings_disabled ( ) {
549+ let test = Test :: msvc ( ) ;
550+ test. gcc ( ) . warnings ( false ) . file ( "foo.c" ) . compile ( "foo" ) ;
551+
552+ test. cmd ( 0 ) . must_have ( "-W0" ) . must_not_have ( "-W4" ) ;
553+ }
554+
536555// Disable this test with the parallel feature because the execution
537556// order is not deterministic.
538557#[ cfg( not( feature = "parallel" ) ) ]
You can’t perform that action at this time.
0 commit comments