This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
libstdc++/1897: basic_ostream operators contain non-ISO-standard variable length arrays.
- To: gcc-gnats at gcc dot gnu dot org
- Subject: libstdc++/1897: basic_ostream operators contain non-ISO-standard variable length arrays.
- From: bumgard at roguewave dot com
- Date: 7 Feb 2001 01:59:41 -0000
- Reply-To: bumgard at roguewave dot com
>Number: 1897
>Category: libstdc++
>Synopsis: basic_ostream operators contain non-ISO-standard variable length arrays.
>Confidential: no
>Severity: serious
>Priority: medium
>Responsible: unassigned
>State: open
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Tue Feb 06 18:06:01 PST 2001
>Closed-Date:
>Last-Modified:
>Originator: Greg Bumgardner
>Release: 2.97 (2000-02-06)
>Organization:
>Environment:
N/A
>Description:
The operator implementations contained in bits/ostream.tcc
contain numerous declarations of variable-length arrays.
The specific instances may be located by searching for the
variable "__pads".
Variable-length arrays are a GCC extension that violate the
ISO language standard.
This poses a problem for users who wish to compile their
code with -pedantic and -Werror.
>How-To-Repeat:
Instantiate basic_ostream<> operators while compiling with
-pedantic.
>Fix:
One possible fix is to replace the various variable-length
array declarations with a dyanmic allocation (though this
would open the code to problems with heap contention):
_CharT __pads[...]; // NON-STANDARD
Replace with:
auto_ptr<_CharT> __dyn(new _CharT[...]);
_CharT* __pads = __dyn.get();
This will leave the rest of the code untouched, and yet will
insure that the storage is recovered at block exit.
The other alternative is to use the non-standard alloca()
funtion. Use of this function won't produce compiler
warnings but may not be portable:
_CharT __pads[...]; // NON-STANDARD
could be replaced with:
_CharT* __pads = static_cast<_CharT*>(alloca(sizeof(_CharT)*length));
>Release-Note:
>Audit-Trail:
>Unformatted: