libstdc++/1972: Exceptions classes need to copy string argument.
bumgard@roguewave.com
bumgard@roguewave.com
Tue Feb 13 20:26:00 GMT 2001
>Number: 1972
>Category: libstdc++
>Synopsis: Exceptions classes need to copy string argument.
>Confidential: no
>Severity: serious
>Priority: medium
>Responsible: unassigned
>State: open
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Tue Feb 13 20:26:01 PST 2001
>Closed-Date:
>Last-Modified:
>Originator: Gregory Bumgardner
>Release: gcc-3_0-branch as of 20010213
>Organization:
>Environment:
N/A
>Description:
The new implementation of the standard exceptions use a
const string& reference to store the const string& __arg
message parameter passed into the constructor.
This means that the exception will be referencing a
a string object that may be a temporary that will be
destroyed when the exception is thrown.
The exceptions must store a copy of the string or its
c_str() contents.
>How-To-Repeat:
Throw one of the standard exceptions passing in a temporary
string object for the "what" message.
>Fix:
Give the logic_error and runtime_error classes a string
instance member that is initialized using a copy constructor,
or use a pointer to a string or a pointer to a char string
and dynamically allocate the appropriate copy, and free this
object or array in the destructor.
The second approach eliminates the need to include the full
string declaration, but this probably isn't needed, as most
code that requires the exception classes is probably
constructing a string to pass in anyway.
>Release-Note:
>Audit-Trail:
>Unformatted:
More information about the Gcc-bugs
mailing list