From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 31402 invoked by alias); 19 May 2003 13:36:02 -0000 Mailing-List: contact gcc-prs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Archive: List-Post: List-Help: Sender: gcc-prs-owner@gcc.gnu.org Received: (qmail 31290 invoked by uid 71); 19 May 2003 13:36:00 -0000 Date: Mon, 19 May 2003 13:36:00 -0000 Message-ID: <20030519133600.31289.qmail@sources.redhat.com> To: nobody@gcc.gnu.org Cc: gcc-prs@gcc.gnu.org, From: "Giovanni Bajo" Subject: Re: c++/10065: -pedantic has strange side effects; what is accepted in -std=c++98 Reply-To: "Giovanni Bajo" X-SW-Source: 2003-05/txt/msg02079.txt.bz2 List-Id: The following reply was made to PR c++/10065; it has been noted by GNATS. From: "Giovanni Bajo" To: "Baldwin, Arthur W" , , , , 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 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