develooper Front page | perl.perl5.porters | Postings from June 2021

Re: C99

Thread Previous | Thread Next
From:
Nicholas Clark
Date:
June 11, 2021 16:46
Subject:
Re: C99
Message ID:
20210611164640.GH16703@etla.org
On Thu, May 20, 2021 at 02:19:01AM +0100, Dagfinn Ilmari Mannsåker wrote:
> Nicholas Clark <nick@ccl4.org> writes:
> 
> > On Wed, May 19, 2021 at 07:21:04PM +0200, Tomasz Konojacki wrote:
> >
> >> I think not only we shouldn't use them, but also we should explictly ban
> >> them with something like "-Wvla -Werror=vla".
> >
> > Yes, I think that this is a good idea. I'm not going to look into it
> > right now, but I will try to remember to, and figure out what to probe
> > for, and where in our setup.
> >
> > (Unless anyone else wants to beat me to it.)
> 
> https://github.com/Perl/perl5/blob/v5.33.9/cflags.SH#L181

commit 7886147fdc48d029686af31c71c808adad1a5737 (HEAD -> blead, origin/blead, origin/HEAD)
Author: Nicholas Clark <nick@ccl4.org>
Date:   Fri Jun 11 12:17:44 2021 +0000

    Add -Werror=vla by default. C99 variable-length arrays are dangerous.

    C11 makes them optional, and MSVC doesn't support them. We can't use them
    (but even if we could, we should not).

diff --git a/cflags.SH b/cflags.SH
index 96bfcd928b..162538583d 100755
--- a/cflags.SH
+++ b/cflags.SH
@@ -180,6 +180,7 @@ Intel*) ;; # # Is that you, Intel C++?
 #
 *) warns="-std=c89 -ansi $pedantic \
        -Werror=pointer-arith \
+       -Werror=vla \
        -Wextra -W \
        -Wc++-compat -Wwrite-strings"
    # declaration after statement is normal in C++ rather than an


I win!

I wasn't even trying to win.

(Also tested on on gcc 4.6.1 on AIX, which happens to have -Werror=vla
How old a gcc would I need to find to *not* have it?)

Nicholas Clark

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About