c++/7471: exception specification violation error when using function try block
aeonflux@roadfly.com
aeonflux@roadfly.com
Fri Aug 2 07:36:00 GMT 2002
>Number: 7471
>Category: c++
>Synopsis: exception specification violation error when using function try block
>Confidential: no
>Severity: serious
>Priority: medium
>Responsible: unassigned
>State: open
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Fri Aug 02 07:36:01 PDT 2002
>Closed-Date:
>Last-Modified:
>Originator: Paul Braman <aeonflux@roadfly.com>
>Release: 2.95/3.x
>Organization:
>Environment:
Red Hat Linux 7.3, plus outside verification
>Description:
An exception that is thrown from a function try block may violate an exception specification before it can be remapped inside the catch block.
If the try and catch blocks are scoped within the function, the code will not violate the exception specification (the correct behavior).
>How-To-Repeat:
The following code demonstrates the problem.
01: #include <iostream>
02: namespace {
03: void something () throw (long)
04: try {
05: throw int (1); // vioates ES
06: } catch (int) {
07: throw long (1); // remaps to non-violation
08: }
09: }
10: int main ()
11: try {
12: something ();
13: return 0;
14: } catch (long) {
15: std::cout << "caught" << std::endl;
16: return 1;
17: }
This code should execute and display "caught" to standard output. However, the code will crash according to the exception specification violation rules.
By making the following changes to the program...
03: void something () throw (long) {
08: } }
...(note the extra level of scope), the compiled program will execute normally.
>Fix:
>Release-Note:
>Audit-Trail:
>Unformatted:
More information about the Gcc-bugs
mailing list