|
|
|
|
||||||
![]() |
|
|
LinkBack | Outils de la discussion |
|
|
#1 |
|
Messages: n/a
Hébergeur: |
Hi,
[I posted this in comp.std.c++ but the post never appeared. So trying here] ISO/IEC 14882:2003 Section 3.4.1/13 has the following [...] Names declared in the outermost block of the function definition are not found when looked up in the scope of a handler for the function-try-block. [Note: but function parameter names are found. ] I thought the following example illustrated the above point but all the compilers (gcc 3.4.2, MS VC++ 2005, Comeau online compiler) I tried it with accept the code without any errors. int main() { int x; try { // ... } catch(...) { int i = x; // Should lookup of 'x' fail here??? //... } return 0; } Please explain what the above sentence from 3.4.1/13 really implies (possibly with a small code example). Thanks, Murali |
|
|
|
#2 |
|
Messages: n/a
Hébergeur: |
On 2008-02-05 15:28:29 -0500, murali.desikan@gmail.com said:
> Hi, > > [I posted this in comp.std.c++ but the post never appeared. So trying > here] > > ISO/IEC 14882:2003 Section 3.4.1/13 has the following > > [...] Names declared in the outermost block of the function definition > are not found when looked up in the scope > of a handler for the function-try-block. [Note: but function parameter > names are found. ] > > I thought the following example illustrated the above point but all > the compilers (gcc 3.4.2, MS VC++ 2005, Comeau online compiler) I > tried it with accept the code without any errors. > > int main() > { > int x; > > try { > // ... > } This isn't a function-try-block. A function-try-block is a rather unusual creature. Here's an example from the standard: class C { int i; double d; public: C(int, double); }; C::C(int ii, double id) try : i(f(ii)), d(f(id)) { // constructor statements } catch(...) { // handles exceptions thrown from the ctor-initializer // and from the constructor statements } -- Pete Roundhouse Consulting, Ltd. (www.versatilecoding.com) Author of "The Standard C++ Library Extensions: a Tutorial and Reference (www.petebecker.com/tr1book) |
|
|
|
#3 |
|
Messages: n/a
Hébergeur: |
On 2008-02-05 21:28, murali.desikan@gmail.com wrote:
> Hi, > > [I posted this in comp.std.c++ but the post never appeared. So trying > here] > > ISO/IEC 14882:2003 Section 3.4.1/13 has the following > > [...] Names declared in the outermost block of the function definition > are not found when looked up in the scope > of a handler for the function-try-block. [Note: but function parameter > names are found. ] > > I thought the following example illustrated the above point but all > the compilers (gcc 3.4.2, MS VC++ 2005, Comeau online compiler) I > tried it with accept the code without any errors. > > int main() > { > int x; > > try { > // ... > } > catch(...) { > int i = x; // Should lookup of 'x' fail here??? > //... > } > > return 0; > } > > Please explain what the above sentence from 3.4.1/13 really implies > (possibly with a small code example). I do not know what they mean by that sentence but what you have is not a function-try-block, just a try-block. A function try block looks something like this: struct A { int i; A(int j); }; A::A(int j) try // <-- OBS : i(j) { throw 1; } catch (int e) { e = i; } -- Erik Wikström |
|
|
|
#4 |
|
Messages: n/a
Hébergeur: |
On Feb 6, 2:27 am, Pete Becker <p...@versatilecoding.com> wrote:
> This isn't a function-try-block. A function-try-block is a rather > unusual creature. Here's an example from the standard: > Thanks for the clarification. Guess I have to be more careful in reading the standard since each term has a precise meaning. Thanks, Murali |
|
|
|
#5 |
|
Messages: n/a
Hébergeur: |
On Feb 6, 2:28 am, Erik Wikström <Erik-wikst...@telia.com> wrote:
> > I do not know what they mean by that sentence but what you have is not a > function-try-block, just a try-block. A function try block looks > something like this: > Thanks for the inputs. Based on this, I think the sentence from 3.4.1/13 becomes clear. Since the entire block of the function definition in a function-try-block corresponds to a try block, any declaration in that block will not be found in the scope of a handler for that block. Thanks, Murali |
|
![]() |
| Outils de la discussion | |
|
|