Skip to content

Commit

Permalink
t/porting/cpphdrcheck.t: fix cc version fallback
Browse files Browse the repository at this point in the history
The `unless ($ver)` check doesn't work as intended because
`` `$cc -V 2>&1` `` captures stderr (intentionally, for Sun C). This
means with gcc or clang `$ver` ends up containing a true-ish string,
either

    gcc: error: unrecognized command-line option ‘-V’
    gcc: fatal error: no input files
    compilation terminated.

or

    clang: error: argument to '-V' is missing (expected 1 value)
    clang: error: no input files

so the `$cc --version` fallback never runs.

Checking for a non-zero exit status and the word "error" in the output
seems to work reliably, though.
  • Loading branch information
mauke committed Aug 1, 2024
1 parent 3bcea52 commit 9cca022
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion t/porting/cpphdrcheck.t
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ sub find_ccpp ($cc) {
# intel C, Sun C
# Sun C sends -V output to stderr
my $ver = `$cc -V 2>&1`;
unless ($ver) {
if (!$ver || ($? && $ver =~ /\berror\b/)) {
# gcc, clang
$ver = `$cc --version 2>$devnull`;
}
Expand Down

0 comments on commit 9cca022

Please sign in to comment.