rfg@MCC.COM (Ron Guilmette) (03/13/89)
When compiled with the G++ 1.34.0/Sun3 compiler, the following short code gets no errors. It should elicit a compile-time error on the indicated line. Note that an error *is* produced if the declaration of "c_object_1" is removed from the code. The fact that no error is issued causes further problems at run-time. Specifically, execution of test() will result in two destructor calls, but only one call to the constructor for the type "c". /* Description - check that "it is not possible to transfer control past a declaration with an (implicit or explicit) initializer" as called for by the "manual", section 9.11, page 296. */ class c { public: c (int i); ~c (); }; void test () { c c_object_1(1); goto lbl; // ERROR c c_object_2 (2); lbl: ; } // Ron Guilmette - MCC - Experimental (parallel) Systems Kit Project // 3500 West Balcones Center Drive, Austin, TX 78759 - (512)338-3740 // ARPA: rfg@mcc.com // UUCP: {rutgers,uunet,gatech,ames,pyramid}!cs.utexas.edu!pp!rfg
rfg@MCC.COM (Ron Guilmette) (03/13/89)
This error is related to (but different from) the last one I posted regarding goto's jumping around object declarations. In this case, G++ 1.34.0/Sun3 fails to issue an error when an "unstructured" switch statement causes an apparently bogus transfer of control past a declaration/initialization. If an error message is ever issued for this condition, it seems like it should be issued for the line indicated below. /* Description - check that "it is not possible to transfer control past a declaration with an (implicit or explicit) initializer" as called for by the "manual", section 9.11, page 296. This test checks that legal but "unstructured" forms of switch statements are not allowed to circumvent the transfer rules for goto statements. */ class c { public: c (int i); ~c (); }; void test () { switch (1) { case 0: { c c_object (1); case 1: // ERROR - case in wrong binding contour break; } } }