From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 19515 invoked by alias); 9 Apr 2003 18:06:00 -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 19486 invoked by uid 71); 9 Apr 2003 18:06:00 -0000 Date: Wed, 09 Apr 2003 18:06:00 -0000 Message-ID: <20030409180600.19485.qmail@sources.redhat.com> To: nobody@gcc.gnu.org Cc: gcc-prs@gcc.gnu.org, From: "Giovanni Bajo" Subject: Re: libstdc++/10361: ifstream get function failure Reply-To: "Giovanni Bajo" X-SW-Source: 2003-04/txt/msg00379.txt.bz2 List-Id: The following reply was made to PR libstdc++/10361; it has been noted by GNATS. From: "Giovanni Bajo" To: , , , , , Cc: Subject: Re: libstdc++/10361: ifstream get function failure Date: Wed, 9 Apr 2003 19:57:04 +0200 http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&p r=10361 Dina Duhovny: >It IS a BUG. If function 'get(char&)' does not read EOL if it appeares > solely in a line, then either you should change the documentation to say > so (and call it a "feature") or call it by its name and fix it. That's _your_ opinion. Official C++ standard says, at ยง27.6.1.3: basic_istream& get(basic_streambuf& sb, char_type delim ); "Extracts characters and inserts them in the output sequence controlled by sb. Characters are extracted and inserted until any of the following occurs: [...] -- c == delim for the next available input character c (in which case c is not extracted); [...] If the function inserts no characters, it calls setstate(failbit), [...]". Since a blank line only has a "\n", the function will extract no characters, and thus will set failbit. You don't clear the failbit, so the function fails next time immediatly; you keep waiting for eof, which will never occur since no more characters will be read. To avoid the infinite loop, you should check simply for !pdb instead of !pdb.eof(). Besides, there is a better way to do what you're trying to do: just use ifstream::getline(). First, getline() silently skips "\n", so you don't have to explicitally call get() to ignore the "\n". Second, it sets the failbit if no characters are _EXTRACTED_ from the stream, instead of _STORED_ like get(). So, in case of a blank line, the "\n" is extracted and silently skipped, the function returns and failbit is not set, so everything continues as usual. > Remember, it worked (as it should) before 3.0. It means that your code was relying on a bug present in libstdc++ before 3.0 It does not mean that your code should work. Giovanni Bajo