public inbox for gcc-prs@sourceware.org
help / color / mirror / Atom feed
* Re: c++/10065: -pedantic has strange side effects; what is accepted in -std=c++98
@ 2003-03-22 4:22 bangerth
0 siblings, 0 replies; 3+ messages in thread
From: bangerth @ 2003-03-22 4:22 UTC (permalink / raw)
To: arthur.baldwin, gcc-bugs, gcc-prs, nobody
Old Synopsis: gcc/g++ issues error instead of warning on non-ISO array assignment.
New Synopsis: -pedantic has strange side effects; what is accepted in -std=c++98
State-Changed-From-To: open->analyzed
State-Changed-By: bangerth
State-Changed-When: Sat Mar 22 04:22:53 2003
State-Changed-Why:
Confirmed, kind of. First thing of course is that
-pedantic converts errors into warnings. This has been
shown in other PRs previously.
That gcc doesn't allow array copies any more is a
feature -- i.e., it is an extension of earlier versions
that was abandoned.
The thing with variably sized arrays: I think this is in
deferrence to C99. However, it is also accepted by g++
with -std=c++98, which I think is wrong.
W.
http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&pr=10065
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: c++/10065: -pedantic has strange side effects; what is accepted in -std=c++98
@ 2003-05-16 1:59 giovannibajo
0 siblings, 0 replies; 3+ messages in thread
From: giovannibajo @ 2003-05-16 1:59 UTC (permalink / raw)
To: arthur.baldwin, gcc-bugs, gcc-prs, nobody
Synopsis: -pedantic has strange side effects; what is accepted in -std=c++98
State-Changed-From-To: analyzed->closed
State-Changed-By: bajo
State-Changed-When: Fri May 16 01:59:54 2003
State-Changed-Why:
Can't see a reason to keep this open. The problem with
-pedantic converting errors to warning is already handled
in c++/10032.
Variable sized array are not supposed to be disabled with
-ansi or -std=c++98 because they can't possibly conflict
with well-formed ISO programs. The official way to disable
extension is to use -pedantic, and -pedantic correctly
reports a warning about it.
http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&pr=10065
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: c++/10065: -pedantic has strange side effects; what is accepted in -std=c++98
@ 2003-05-19 13:36 Giovanni Bajo
0 siblings, 0 replies; 3+ messages in thread
From: Giovanni Bajo @ 2003-05-19 13:36 UTC (permalink / raw)
To: nobody; +Cc: gcc-prs
The following reply was made to PR c++/10065; it has been noted by GNATS.
From: "Giovanni Bajo" <giovannibajo@libero.it>
To: "Baldwin, Arthur W" <Arthur.Baldwin@gd-ais.com>,
<gcc-bugs@gcc.gnu.org>,
<gcc-prs@gcc.gnu.org>,
<nobody@gcc.gnu.org>,
<gcc-gnats@gcc.gnu.org>
Cc:
Subject: Re: c++/10065: -pedantic has strange side effects; what is accepted in -std=c++98
Date: Mon, 19 May 2003 15:27:06 +0200
Baldwin, Arthur W <Arthur.Baldwin@gd-ais.com> wrote:
> I do not understand the resolution of this problem. The response below
says
> in part:
>
> Variable sized array are not supposed to be disabled with
> -ansi or -std=c++98 because they can't possibly conflict
> with well-formed ISO programs.
>
> The reason I reported the issue is that I cannot compile a program with
> variable sized arrays with flags such as -ansi or -std=c++98. The
compiler
> (gcc-3.2.2 on Linux) issues errors and aborts the build. With -pedantic,
> however, I get a warning, but the build completes. Older versions of the
> compiler handled the variable sized arrays without any flags.
Sorry if I wasn't clear. There are two different issues in your code:
*************************
First issue (within main()): you are assigning arrays (lines 19 "y = x", and
28 "y2 = x2"). This is forbidden by ISO C++ standard. GCC correctly emits an
error about this:
arrayTest.cc:19: ISO C++ forbids assignment of arrays
arrayTest.cc:28: ISO C++ forbids assignment of arrays
Now, this is a hard error, as it should be. The workaround is memcpy(), of
course. *BUT*, GCC currently has a bug: when you add -pedantic, some errors
magically turns into warnings (this very problem is tracked by PR10032). So
your compilation incorrectly succeeds with -pedantic because of this bug.
This behaviour has nothing to do with -ansi or -std, becuase they don't have
this magic bug. You can isolate your main() function into a separate file,
and experiment with it to check what I'm saying. As you can see, this
funciton does not contain variable length arrays, so it has nothing to do
with it (and the error message does not speak about variable length array,
it speaks about assignment of arrays).
*************************
Second issue (within printMatrix()): you are using variable lentgh arrays
here. This is a GCC extension, so it is accepted by GCC. -ansi (or -std)
turn off _only_ GCC extensions that might conflict (as in: change the
meaning / reject) of a well-formed ISO C++ program. Since a well-formed ISO
C++ program would be invalid with variable length array, this extension does
not conflict with the standard in any way, and it is not turned off
with -ansi/-std. If one wants to disable GCC extension altogether, the right
option is "-pedantic" (or "-pedantic-errors"). When you put "-pedantic" on
the command line, GCC emits a warning about your variable length arrays (as
it should):
arrayTest.cc:38: warning: ISO C++ forbids variable-size array `matrixType'
arrayTest.cc:38: warning: ISO C++ forbids variable-size array `matrixType'
If you put "-pedantic-error", it emits an error about it (as it should).
Everything works as expected. You can isolate your printMatrix() function
and check this behaviour.
> The question is: Does gcc support variable sized arrays or not,
Yes, and it works for you in fact. Exactly like it should.
> and will
> the compiler support the variable sized arrays into the future?
I can't foresee the future, but if it will be ever removed, be sure that
there will be some deprecation warning for at least one major version. For
now, it's ok.
> We have
> legacy, delivered code that exploits the variable-sized array capability
of
> an older compiler, and I have to know whether we should prepare to rewrite
> the code in a maintenance upgrade when we evolve to a new OS and new
> compiler. At the moment, the only way I could redeliver the code would be
> to compile with -pedantic, and then explain away the warnings. Without
> -pedantic, IT WON'T COMPILE.
This has _nothing_ to do with variable length array. Your code is ill-formed
because it copies two arrays, in line 19 and 28. I don't know if this used
to be a GCC extension, but surely it is not anymore. You should rewrite your
code in those lines to use memcpy().
The fact that it works with -pedantic is only a side effect of the bug
tracked by PR10032 (-pedantic sometimes incorrectly turns errors into
warnings, allowing compilation of ill-formed code).
> Sorry if I'm being dense about the response, but it doesn't seem to
address
> my concern.
I hope that everything is clear now. The only issue in your PR is
about -pendatic turning errors into warnings, and it's already tracked by
another open PR. So I closed yours.
Giovanni Bajo
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2003-05-19 13:36 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-03-22 4:22 c++/10065: -pedantic has strange side effects; what is accepted in -std=c++98 bangerth
2003-05-16 1:59 giovannibajo
2003-05-19 13:36 Giovanni Bajo
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).