Re: STL and "function try blocks"



"Babak Pourat" <pourat@xxxxxxxxxxxxxxxxxxxx> schrieb im Newsbeitrag
news:466bgpF9hsfbU1@xxxxxxxxxxxxxxxxx
Hallo

the following code does not compile (VC 7.1):

#include <vector>

int testTry() try{
std::vector<int> *x = new std::vector<int>;
delete x;
return 0;
}catch (...) {
return 0;
}

int main(){
return 0;
}


d:\tmp\trytst\trytst\trytst.cpp(11) : warning C4091: '' : ignored on left
of 'int' when no variable is declared
d:\tmp\trytst\trytst\trytst.cpp(11) : error C2143: syntax error : missing
';' before 'inline function header'

Does any one understand why it compiles if I delete the "delete x;"
statement?

No. I can only guess that the compiler is confused. It really looks like a
compiler bug. It is valid code and accepted by other compilers, like Comeau.
But there are two workarounds the problem:

1. Don't use function-try-blocks unless you really have to.
2. Insert a semicolon after the end of the catch (and before int main). This
is not required by the language, and strictly speaking the program will be
no valid C++ any longer, but if the compiler likes it better.

Perhaps there is also

3. Upgrade to VC8, but I don't know if the bug has been fixed.

HTH
Heinz


.



Relevant Pages

  • Re: syslog-ng 3.5.3 installation on solaris10, i386
    ... configure:3612: checking for gcc ... configure:3908: checking whether the C compiler works ... | #ifdef YY_USE_CONST ... | * int a single C statement. ...
    (comp.unix.solaris)
  • Re: It Pays to Enrich Your C Skills
    ... Check if you can score a perfect 10 (without using a compiler). ... int main{ ... struct bitfield { ... out if it is a negative integer constant or a constant expression ...
    (comp.lang.c.moderated)
  • OT: Re: Perl Peeves
    ... I see the result of a test being used as an int. ... the compiler just assumed you knew what you were doing ... introduced to the language later, so void * was unheard of in most code. ... This didn't mean bool was special, declaring it just signaled to the ...
    (comp.lang.perl.misc)
  • Re: OT: Re: Perl Peeves
    ... when I see the result of a test being used as an int. ... compiler just assumed you knew what you were doing and would ... This didn't mean bool was special, declaring it just signaled to the ... What "normalization of bool results is built into the compiler"? ...
    (comp.lang.perl.misc)
  • Fwd: Xlib example program compile error
    ... Here is the compiler output for xctest.c as it is written in the book. ... xctest.c:163: `theMain' undeclared ... XWIN *MakeXButton(int x, int y, unsigned height, unsigned bdwidth, ... Window parent, char *text, int, ...
    (comp.os.msdos.djgpp)