Skip to content

Commit

Permalink
Test for compiling without warnings against public headers
Browse files Browse the repository at this point in the history
Under compilers with WERRORFLAG, MakeMakefile.try_compile treats
warnings as errors, so we can use append_cflags to test whether the
public header files emit warnings with certain flags turned on.

[Regression test for feature #20507]
  • Loading branch information
flavorjones committed May 27, 2024
1 parent 3fa9a1c commit 69ca057
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions ext/-test-/public_header_warnings/extconf.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#
# Under compilers with WERRORFLAG, MakeMakefile.try_compile treats warnings as errors, so we can
# use append_cflags to test whether the public header files emit warnings with certain flags turned
# on.
#
def check_append_cflags(flag, msg = nil)
msg ||= "flag #{flag} is not acceptable"
!$CFLAGS.include?(flag) or raise("flag #{flag} already present in $CFLAGS")
append_cflags(flag)
$CFLAGS.include?(flag) or raise(msg)
end

if %w[gcc clang].include?(RbConfig::CONFIG['CC'])
config_string("WERRORFLAG") or raise("expected WERRORFLAG to be defined")

# should be acceptable on all modern C compilers
check_append_cflags("-D_TEST_OK", "baseline compiler warning test failed")

# Feature #20507: Allow compilation of C extensions with -Wconversion
check_append_cflags("-Wconversion", "-Wconversion raising warnings in public headers")
end

create_makefile("-test-/public_header_warnings")

0 comments on commit 69ca057

Please sign in to comment.