You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@perl.apache.org by "Philip M. Gollucci" <pg...@p6m7g8.com> on 2005/08/12 07:21:54 UTC

-Wdeclaration-after-statement Final version

Third and final take.  No objects and I'll commit.  I combined all 3 of 
the verions. :) Who would have thought something so small would take so 
long?


===================================================================
--- lib/Apache2/Build.pm        (revision 230957)
+++ lib/Apache2/Build.pm        (working copy)
@@ -518,10 +518,21 @@

      if ($self->{MP_MAINTAINER}) {
          $self->{MP_DEBUG} = 1;
-        if ($self->perl_config('gccversion')) {
+
+        if (my $gccversion = $self->perl_config('gccversion')) {
              #same as --with-maintainter-mode
              $ccopts .= " $Wall -DAP_DEBUG";
              $ccopts .= " -DAP_HAVE_DESIGNATED_INITIALIZER";
+
+            my ($gcc_major, $gcc_minor, $gcc_patch) =
+                $gccversion =~ /^(\d)\.(\d+)\.(\d+)/;
+
+            my $gccversion_decimal = $gcc_major .
+                $gcc_minor . $gcc_patch;
+
+            ## GCC 3.3.2+
+            if ($gccversion_decimal > 332) {
+              $ccopts .= " -Wdeclaration-after-statement";
+            }
          }
      }



-- 
END
------------------------------------------------------------
     What doesn't kill us can only make us stronger.
                 Nothing is impossible.
				
Philip M. Gollucci (pgollucci@p6m7g8.com) 301.254.5198
Consultant / http://p6m7g8.net/Resume/
Senior Developer / Liquidity Services, Inc.
   http://www.liquidityservicesinc.com
        http://www.liquidation.com
        http://www.uksurplus.com
        http://www.govliquidation.com
        http://www.gowholesale.com

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org


Re: -Wdeclaration-after-statement Final version

Posted by "Philippe M. Chiasson" <go...@ectoplasm.org>.
Philip M. Gollucci wrote:
> Philip M. Gollucci wrote:
> 
>> Philippe M. Chiasson wrote:
>> Ah, I did miss it... read right over it. D'oh!
>>
> Here is its again with the return 0 left in as most of the code in
> Build.pm is return 0 though not all.
> Also, using Philippe's cmp_tuples function.

Looks good, with notes below...

> 
> Index: Build.pm
> ===================================================================
> --- Build.pm    (revision 234145)
> +++ Build.pm    (working copy)
> @@ -523,6 +523,11 @@
>              $ccopts .= " $Wall -DAP_DEBUG";
>              $ccopts .= " -DAP_HAVE_DESIGNATED_INITIALIZER";
>          }
> +
> +        if ($self->has_gcc_version('3.3.2') &&
> +            $ccopts !~ /declaration-after-statement/) {
> +            $ccopts .= " -Wdeclaration-after-statement";

		debug "Adding -Wdeclaration-after-statement to ccopts";

> +        }
>      }
> 
>      if ($self->{MP_COMPAT_1X}) {
> @@ -555,6 +560,33 @@
>      $ccopts;
>  }
> 
> +sub has_gcc_version {
> +
> +    my $self = shift;
> +    my $requested_version = shift;
> +
> +    my $has_version = $self->perl_config('gccversion');
> +
> +    return 0 unless $has_version;
> +
> +    my ($has_major, $has_minor, $has_patch) = split /\./, $has_version, 3;
> +    my ($r_major, $r_minor, $r_patch) = split /\./, $requested_version, 3;

Again, why not a simpler:

my @tuples = split /\./, $has_version;
my @r_tuples = split /\./, $requested_version;

> +    return &cmp_tuples(\@tuples, \@r_tuples) == 1;

return cmp_tuples(); The '&' isn't necessary.

> +}
> +
> +sub cmp_tuples {
> +
> +    my ($a, $b) = @_;
> +
> +    while(@$a && @$b) {
> +        my $cmp = shift @$a <=> shift @$b;
> +        return $cmp if $cmp;
> +    }
> +
> +    return @$a <=> @$b;
> +}
> +

Otherwise, +1

--------------------------------------------------------------------------------
Philippe M. Chiasson m/gozer\@(apache|cpan|ectoplasm)\.org/ GPG KeyID : 88C3A5A5
http://gozer.ectoplasm.org/     F9BF E0C2 480E 7680 1AE5 3631 CB32 A107 88C3A5A5

Re: -Wdeclaration-after-statement Final version

Posted by "Philip M. Gollucci" <pg...@p6m7g8.com>.
Philip M. Gollucci wrote:
> Philippe M. Chiasson wrote:
> Ah, I did miss it... read right over it. D'oh!
> 
Here is its again with the return 0 left in as most of the code in Build.pm is return 0 though not all.
Also, using Philippe's cmp_tuples function.


Index: Build.pm
===================================================================
--- Build.pm    (revision 234145)
+++ Build.pm    (working copy)
@@ -523,6 +523,11 @@
              $ccopts .= " $Wall -DAP_DEBUG";
              $ccopts .= " -DAP_HAVE_DESIGNATED_INITIALIZER";
          }
+
+        if ($self->has_gcc_version('3.3.2') &&
+            $ccopts !~ /declaration-after-statement/) {
+            $ccopts .= " -Wdeclaration-after-statement";
+        }
      }

      if ($self->{MP_COMPAT_1X}) {
@@ -555,6 +560,33 @@
      $ccopts;
  }

+sub has_gcc_version {
+
+    my $self = shift;
+    my $requested_version = shift;
+
+    my $has_version = $self->perl_config('gccversion');
+
+    return 0 unless $has_version;
+
+    my ($has_major, $has_minor, $has_patch) = split /\./, $has_version, 3;
+    my ($r_major, $r_minor, $r_patch) = split /\./, $requested_version, 3;
+
+    return &cmp_tuples(\@tuples, \@r_tuples) == 1;
+}
+
+sub cmp_tuples {
+
+    my ($a, $b) = @_;
+
+    while(@$a && @$b) {
+        my $cmp = shift @$a <=> shift @$b;
+        return $cmp if $cmp;
+    }
+
+    return @$a <=> @$b;
+}
+

-- 
END
------------------------------------------------------------
     What doesn't kill us can only make us stronger.
                 Nothing is impossible.
				
Philip M. Gollucci (pgollucci@p6m7g8.com) 301.254.5198
Consultant / http://p6m7g8.net/Resume/
Senior Developer / Liquidity Services, Inc.
   http://www.liquidityservicesinc.com
        http://www.liquidation.com
        http://www.uksurplus.com
        http://www.govliquidation.com
        http://www.gowholesale.com


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org


Re: -Wdeclaration-after-statement Final version

Posted by "Philip M. Gollucci" <pg...@p6m7g8.com>.
Philippe M. Chiasson wrote:
> That was by design, to keep the behaviour of <=> or cmp

> You must have missed this bit:
> 
> return cmp_tuples(\@tuples, \@r_tuples) == 1;
> 
> Where I specifically check that @tuples is greater than @r_tuples.
> 
> Figured this cmp_tuples() migth also be used to check if something
> is less than something else.
Ah, I did miss it... read right over it. D'oh!

-- 
END
------------------------------------------------------------
     What doesn't kill us can only make us stronger.
                 Nothing is impossible.
				
Philip M. Gollucci (pgollucci@p6m7g8.com) 301.254.5198
Consultant / http://p6m7g8.net/Resume/
Senior Developer / Liquidity Services, Inc.
   http://www.liquidityservicesinc.com
        http://www.liquidation.com
        http://www.uksurplus.com
        http://www.govliquidation.com
        http://www.gowholesale.com


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org


Re: -Wdeclaration-after-statement Final version

Posted by "Philippe M. Chiasson" <go...@ectoplasm.org>.
Philip M. Gollucci wrote:
> Philippe M. Chiasson wrote:
> 
>> Isn't "return;" the more canonical way of returning false ?
> 
> Beats me... I know a lot of the mp2 code particular Apache2::Status as I
> was just digging in there uses return 0.  I really have no preference.

Just looked around the existing code, and yes, you are right, return 0 is
used all over to represent failure, so I guess it's better to be consistent.
>> Minor nit, but wouldn't
>>
>> my @tuples = split /\./, $has_version;
>> my @r_tuples = split /\./, $requested_version;
>>
>> return cmp_tuples(\@tuples, \@r_tuples) == 1;
>>
>> sub cmp_tuples {
>>     my ($a, $b) = @_;
>>
>>     while(@$a && @$b) {
>>         my $cmp = shift @$a <=> shift @$b;
>>         return $cmp if $cmp;
>>     }
>>     return @$a <=> @$b;
>> }
>>
>> Be a more generic approach that would also work if there is ever a
>> gcc-4.0.0.1 and could possibly be used to refactor some more version
>> comparaisons ?
> 
> More generic yes.  But working no. :)
> 
> <=> returns 1, 0, -1, and undef for NaN.
> both 1 and -1 are true in perl.

That was by design, to keep the behaviour of <=> or cmp

> That should be
>>         return $cmp if $cmp;
> return 1 if $cmp == 1;
> 
> Whith that minor change, I agree.

You must have missed this bit:

return cmp_tuples(\@tuples, \@r_tuples) == 1;

Where I specifically check that @tuples is greater than @r_tuples.

Figured this cmp_tuples() migth also be used to check if something
is less than something else.

--------------------------------------------------------------------------------
Philippe M. Chiasson m/gozer\@(apache|cpan|ectoplasm)\.org/ GPG KeyID : 88C3A5A5
http://gozer.ectoplasm.org/     F9BF E0C2 480E 7680 1AE5 3631 CB32 A107 88C3A5A5

Re: -Wdeclaration-after-statement Final version

Posted by Geoffrey Young <ge...@modperlcookbook.org>.

Andy_Bach@wiwb.uscourts.gov wrote:
>>>Isn't "return;" the more canonical way of returning false ?
>>
>>Beats me... I know a lot of the mp2 code particular Apache2::Status as I 
> 
> 
> was just digging in there uses return 0.  I really have no preference.
> 
> Just a note, the new "Perl Best Practices" Damian Conway, suggest a bare 
> return is best.  In particular
> return undef;
> is a bad idea as it'll slip an undef  into list context (so for zero too?) 
> which, he shows, can be problematic.

right - bare return() understands its context and will dtrt when the calling
function expects a list or a scalar, provided you mean to return simply
"false"...

is "false" what we're after here, or an actual 0 value.  false might run
into warnings issues if we try to compare the result in numeric comparisons,
while 0 will not...

--Geoff

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org


Re: -Wdeclaration-after-statement Final version

Posted by An...@wiwb.uscourts.gov.
> > Isn't "return;" the more canonical way of returning false ?
> Beats me... I know a lot of the mp2 code particular Apache2::Status as I 

was just digging in there uses return 0.  I really have no preference.

Just a note, the new "Perl Best Practices" Damian Conway, suggest a bare 
return is best.  In particular
return undef;
is a bad idea as it'll slip an undef  into list context (so for zero too?) 
which, he shows, can be problematic.

Good book.

a

Andy Bach, Sys. Mangler
Internet: andy_bach@wiwb.uscourts.gov 
VOICE: (608) 261-5738  FAX 264-5932

Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible,
 you are,  by definition, not smart enough to debug it. 
-- Brian Kernighan


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org


Re: -Wdeclaration-after-statement Final version

Posted by "Philip M. Gollucci" <pg...@p6m7g8.com>.
Philippe M. Chiasson wrote:
> Isn't "return;" the more canonical way of returning false ?
Beats me... I know a lot of the mp2 code particular Apache2::Status as I 
was just digging in there uses return 0.  I really have no preference.

> 
> Minor nit, but wouldn't
> 
> my @tuples = split /\./, $has_version;
> my @r_tuples = split /\./, $requested_version;
> 
> return cmp_tuples(\@tuples, \@r_tuples) == 1;
> 
> sub cmp_tuples {
>     my ($a, $b) = @_;
> 
>     while(@$a && @$b) {
>         my $cmp = shift @$a <=> shift @$b;
>         return $cmp if $cmp;
>     }
>     return @$a <=> @$b;
> }
> 
> Be a more generic approach that would also work if there is ever a
> gcc-4.0.0.1 and could possibly be used to refactor some more version
> comparaisons ?
More generic yes.  But working no. :)

<=> returns 1, 0, -1, and undef for NaN.
both 1 and -1 are true in perl.

That should be
 >         return $cmp if $cmp;
return 1 if $cmp == 1;

Whith that minor change, I agree.

-- 
END
------------------------------------------------------------
     What doesn't kill us can only make us stronger.
                 Nothing is impossible.
				
Philip M. Gollucci (pgollucci@p6m7g8.com) 301.254.5198
Consultant / http://p6m7g8.net/Resume/
Senior Developer / Liquidity Services, Inc.
   http://www.liquidityservicesinc.com
        http://www.liquidation.com
        http://www.uksurplus.com
        http://www.govliquidation.com
        http://www.gowholesale.com

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org


Re: -Wdeclaration-after-statement Final version

Posted by "Philippe M. Chiasson" <go...@ectoplasm.org>.
Philip M. Gollucci wrote:
> Philippe M. Chiasson wrote:
> 
>> A better patch might be to first check if we already have that option
>> from Perl,
>> otherwise, try and figure out if it's safe to add it ourselves.
> 
> Okay, as requested, I've functionalized this and added a check to make sure
> $ccopts doesn't already contain this compile flag.
> 
> Index: lib/Apache2/Build.pm
> ===================================================================
> --- lib/Apache2/Build.pm        (revision 234145)
> +++ lib/Apache2/Build.pm        (working copy)
> @@ -523,6 +523,11 @@
>              $ccopts .= " $Wall -DAP_DEBUG";
>              $ccopts .= " -DAP_HAVE_DESIGNATED_INITIALIZER";
>          }
> +
> +        if ($self->has_gcc_version('3.3.2') &&
> +            $ccopts !~ /declaration-after-statement/) {
> +            $ccopts .= " -Wdeclaration-after-statement";
> +        }
>      }
> 
>      if ($self->{MP_COMPAT_1X}) {
> @@ -555,6 +560,28 @@
>      $ccopts;
>  }
> 
> +sub has_gcc_version {
> +
> +    my $self = shift;
> +    my $requested_version = shift;
> +
> +    my $has_version = $self->perl_config('gccversion');
> +
> +    return 0 unless $has_version;

Isn't "return;" the more canonical way of returning false ?

> +    my ($has_major, $has_minor, $has_patch) = split /\./, $has_version, 3;
> +    my ($r_major, $r_minor, $r_patch) = split /\./, $requested_version, 3;

Minor nit, but wouldn't

my @tuples = split /\./, $has_version;
my @r_tuples = split /\./, $requested_version;

return cmp_tuples(\@tuples, \@r_tuples) == 1;

sub cmp_tuples {
    my ($a, $b) = @_;

    while(@$a && @$b) {
        my $cmp = shift @$a <=> shift @$b;
        return $cmp if $cmp;
    }
    return @$a <=> @$b;
}

Be a more generic approach that would also work if there is ever a
gcc-4.0.0.1 and could possibly be used to refactor some more version
comparaisons ?

> +    if ($has_major > $r_major ||
> +        ($has_major == $r_major && $has_minor > $r_minor) ||
> +        ($has_major == $r_major && $has_minor == $r_minor
> +            && $has_patch >= $r_patch)) {
> +        return 1;
> +    }
> +    else {
> +        return 0;
> +    }
> +}
> +
>  sub perl_ccopts {
>      my $self = shift;

--------------------------------------------------------------------------------
Philippe M. Chiasson m/gozer\@(apache|cpan|ectoplasm)\.org/ GPG KeyID : 88C3A5A5
http://gozer.ectoplasm.org/     F9BF E0C2 480E 7680 1AE5 3631 CB32 A107 88C3A5A5

Re: -Wdeclaration-after-statement Final version

Posted by "Philip M. Gollucci" <pg...@p6m7g8.com>.
Philippe M. Chiasson wrote:
> A better patch might be to first check if we already have that option from Perl,
> otherwise, try and figure out if it's safe to add it ourselves.
Okay, as requested, I've functionalized this and added a check to make sure
$ccopts doesn't already contain this compile flag.

Index: lib/Apache2/Build.pm
===================================================================
--- lib/Apache2/Build.pm        (revision 234145)
+++ lib/Apache2/Build.pm        (working copy)
@@ -523,6 +523,11 @@
              $ccopts .= " $Wall -DAP_DEBUG";
              $ccopts .= " -DAP_HAVE_DESIGNATED_INITIALIZER";
          }
+
+        if ($self->has_gcc_version('3.3.2') &&
+            $ccopts !~ /declaration-after-statement/) {
+            $ccopts .= " -Wdeclaration-after-statement";
+        }
      }

      if ($self->{MP_COMPAT_1X}) {
@@ -555,6 +560,28 @@
      $ccopts;
  }

+sub has_gcc_version {
+
+    my $self = shift;
+    my $requested_version = shift;
+
+    my $has_version = $self->perl_config('gccversion');
+
+    return 0 unless $has_version;
+
+    my ($has_major, $has_minor, $has_patch) = split /\./, $has_version, 3;
+    my ($r_major, $r_minor, $r_patch) = split /\./, $requested_version, 3;
+
+    if ($has_major > $r_major ||
+        ($has_major == $r_major && $has_minor > $r_minor) ||
+        ($has_major == $r_major && $has_minor == $r_minor
+            && $has_patch >= $r_patch)) {
+        return 1;
+    }
+    else {
+        return 0;
+    }
+}
+
  sub perl_ccopts {
      my $self = shift;



-- 
END
------------------------------------------------------------
     What doesn't kill us can only make us stronger.
                 Nothing is impossible.
				
Philip M. Gollucci (pgollucci@p6m7g8.com) 301.254.5198
Consultant / http://p6m7g8.net/Resume/
Senior Developer / Liquidity Services, Inc.
   http://www.liquidityservicesinc.com
        http://www.liquidation.com
        http://www.uksurplus.com
        http://www.govliquidation.com
        http://www.gowholesale.com


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org


Re: -Wdeclaration-after-statement Final version

Posted by "Philippe M. Chiasson" <go...@ectoplasm.org>.
Philip M. Gollucci wrote:
>> I am not so surprised ;-) I've seen patches take many more iterations
>> than this one before going thru. It's one way to keep the codebase
>> clean and concise (and hopefully bug-free).
> 
> Before I rip more of my hair out, I believe this whole thread is going
> to be moot. *sigh*.

Well, depends on since when Perl started picking this up. My Perl-5.8.6 that
comes with FC4 doesn't expose it in perl -V:ccflags, even though my gcc supports
that option.

A better patch might be to first check if we already have that option from Perl,
otherwise, try and figure out if it's safe to add it ourselves.

> Explanation:
> 
> [...]
> 
> I say the todo is done.

> :)

See above!

> That'll teach me to jump into things :)

Nah, It's still a vaild patch to finalize, IMO.

> P.S.
>   Appologies for the BCC to the list and others last time, picked the
> wrong header type somehow.

np.
--------------------------------------------------------------------------------
Philippe M. Chiasson m/gozer\@(apache|cpan|ectoplasm)\.org/ GPG KeyID : 88C3A5A5
http://gozer.ectoplasm.org/     F9BF E0C2 480E 7680 1AE5 3631 CB32 A107 88C3A5A5

Re: -Wdeclaration-after-statement Final version

Posted by "Philip M. Gollucci" <pg...@p6m7g8.com>.
> I am not so surprised ;-) I've seen patches take many more iterations
> than this one before going thru. It's one way to keep the codebase
> clean and concise (and hopefully bug-free).
Before I rip more of my hair out, I believe this whole thread is going 
to be moot. *sigh*.

Explanation:

svn co ...
[no local changes]
make distclean
[just incase]
perl Makefile.PL ...
make
[snipped]
cc 
-I/usr/home/pgollucci.local/dev/repos/asf/perl/modperl/trunk/src/modules/perl 
-I/usr/home/pgollucci.local/dev/repos/asf/perl/modperl/trunk/xs 
-I/usr/home/pgollucci/dev/apps/5.9.3-ithreads_2.3.0_worker/httpd/include 
-I/usr/home/pgollucci/dev/apps/5.9.3-ithreads_2.3.0_worker/httpd/include 
-I/usr/home/pgollucci.local/dev/repos/asf/httpd/httpd/trunk/srclib/apr-util/../apr-iconv/include 
  -I/usr/local/include 
-I/usr/home/pgollucci/dev/apps/5.9.3-ithreads_2.3.0_worker/httpd/include 
-pipe -DHAS_FPSETMASK -DHAS_FLOATINGPOINT_H -DDEBUGGING 
-fno-strict-aliasing *-Wdeclaration-after-statement* 
-I/usr/local/include 
-I/usr/home/pgollucci/dev/apps/5.9.3-ithreads_2.3.0_worker/perl/lib/CORE 
-DMOD_PERL -Wall -Wmissing-prototypes -Wstrict-prototypes 
-Wmissing-declarations -Werror -DAP_DEBUG 
-DAP_HAVE_DESIGNATED_INITIALIZER -DMP_COMPAT_1X -DMP_DEBUG -DMP_TRACE 
-DAP_DEBUG -ggdb3 -O0 -DPIC -fPIC  -c mod_perl.c && mv mod_perl.o 
mod_perl.lo

You'll notice that its already there.  The reason being is that
we grap PERL's ccflags enmass:

lib/Apache2/Build.pm:
sub perl_ccopts {
     my $self = shift;

     my $cflags = $self->strip_lfs(" $Config{ccflags} ");


 From Perl's ./Configure
echo "Checking if your compiler accepts -Wdeclaration-after-statement" 2>&1
         echo 'int main(void) { return 0; }' > gcctest.c
         if $cc -Wdeclaration-after-statement -o gcctest gcctest.c; then
             echo "Yes, it does." 2>&1
             case "$ccflags" in
             *-Wdeclaration-after-statement*)
                 echo "Leaving current flags $ccflags alone." 2>&1
                 ;;
             *) dflt="$dflt -Wdeclaration-after-statement" ;;
             esac
         else
             echo "Nope, it doesn't, but that's ok." 2>&1
         fi
         ;;

So if we are using GCC and its supported, we get it.

I say the todo is done.

:)

That'll teach me to jump into things :)

P.S.
   Appologies for the BCC to the list and others last time, picked the 
wrong header type somehow.





---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org


Re: -Wdeclaration-after-statement Final version

Posted by "Philippe M. Chiasson" <go...@ectoplasm.org>.
Philip M. Gollucci wrote:
> Third and final take.  No objects and I'll commit.  I combined all 3 of
> the verions. :) Who would have thought something so small would take so
> long?

I am not so surprised ;-) I've seen patches take many more iterations
than this one before going thru. It's one way to keep the codebase
clean and concise (and hopefully bug-free).

> ===================================================================
> --- lib/Apache2/Build.pm        (revision 230957)
> +++ lib/Apache2/Build.pm        (working copy)
> @@ -518,10 +518,21 @@
> 
>      if ($self->{MP_MAINTAINER}) {
>          $self->{MP_DEBUG} = 1;
> -        if ($self->perl_config('gccversion')) {
> +
> +        if (my $gccversion = $self->perl_config('gccversion')) {
>              #same as --with-maintainter-mode
>              $ccopts .= " $Wall -DAP_DEBUG";
>              $ccopts .= " -DAP_HAVE_DESIGNATED_INITIALIZER";
> +
> +            my ($gcc_major, $gcc_minor, $gcc_patch) =
> +                $gccversion =~ /^(\d)\.(\d+)\.(\d+)/;
> +
> +            my $gccversion_decimal = $gcc_major .
> +                $gcc_minor . $gcc_patch;
> +
> +            ## GCC 3.3.2+

if ($gcc_major > 3 ||
    $gcc_major == 3 && (
	$gcc_minor > 3 ||
	    $gcc_minor == 3 &&
		$gcc_patch >= 2 )) {

> +            if ($gccversion_decimal > 332) {
> +              $ccopts .= " -Wdeclaration-after-statement";
> +            }
>          }
>      }

Getting version arithmetic is always a pita, for instance, the decimal concat
version will fail if there is such a thing as gcc-3.2.10 or gcc-2.95.2.

sub check_gcc332_if {
    my $gccversion = shift;
    my ($gcc_major, $gcc_minor, $gcc_patch) =
      $gccversion =~ /^(\d)\.(\d+)\.(\d+)/;

    if (   $gcc_major > 3
        || $gcc_major == 3
        && ($gcc_minor > 3 || $gcc_minor == 3 && $gcc_patch > 2))
    {

        return 1;
    }
    return;
}

sub check_gcc332_dec {
    my $gccversion = shift;
    my ($gcc_major, $gcc_minor, $gcc_patch) =
      $gccversion =~ /^(\d)\.(\d+)\.(\d+)/;
    my $gccversion_decimal = $gcc_major . $gcc_minor . $gcc_patch;
    if ($gccversion_decimal > 332) {
        return 1;
    }
    return;
}

#using version.pm
sub check_gcc332_ver {
    require version;
    my $v = version::qv(shift);
    return $v > version::qv('3.3.2');
}

use Test::More qw(no_plan);

foreach
  my $v (qw(2.3.4 2.96.4 3.0.0 3.1.0 3.2.0 3.3.0 3.3.1 3.3.2 3 3.3.2 3.2.10))
{
    ok !check_gcc332_if($v),  "if $v";
    ok !check_gcc332_dec($v), "dec $v";
    ok !check_gcc332_ver($v), "ver $v";
}
foreach my $v (qw(3.3.3 3.3.10 3.4.10 4.0.0 4.10.1)) {
    ok check_gcc332_if($v),  "if $v";
    ok check_gcc332_dec($v), "dec $v";
    ok check_gcc332_ver($v), "ver $v";
}

--------------------------------------------------------------------------------
Philippe M. Chiasson m/gozer\@(apache|cpan|ectoplasm)\.org/ GPG KeyID : 88C3A5A5
http://gozer.ectoplasm.org/     F9BF E0C2 480E 7680 1AE5 3631 CB32 A107 88C3A5A5