// ---------------------------------------------------------------------- // // forbad.cc - ISOcxx test for old 'for' scoping rules: // // A variable defined inside a for loop should be in the scope of the // loop. It should not conflict with any previously-defined entity of // the same name, nor should it any longer be defined after loop // termination. // // History: // 31-May-1999 WEB Adapt from previous incarnation // 02-Jun-1999 WEB Incorporate syntax.h header to simplify // validation // 07-Jun-1999 WEB Introduce START // 18-Jun-1999 WEB Adopt new name for compliance header // 25-Apr-2001 WEB s//"ISOcxx\/ISOcxxSyntax.hh"/ // // ---------------------------------------------------------------------- #include "ISOcxx/ISOcxxSyntax.hh" int const START( -2 ); int main() { int i( START ); for ( int i( 0 ) // a new i; ought compile ok , sum( 0 ) ; i < 10 ; ++i ) { sum += i; } if ( i != START ) // original i; ought be unchanged return 1; else if ( sum != 45 ) // sum ought be no longer defined; ought not compile return 2; else return 3; // all is well, alas } // main()