| Topic: |
DEVELOP > c-Plus-Plus |
| User: |
"" |
| Date: |
05 Feb 2008 02:28:29 PM |
| Object: |
Unqualified name lookup doubt (ISO/IEC-14882:2003 3.4.1/13) |
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
.
|
|
| User: "Pete Becker" |
|
| Title: Re: Unqualified name lookup doubt (ISO/IEC-14882:2003 3.4.1/13) |
05 Feb 2008 03:27:11 PM |
|
|
On 2008-02-05 15:28:29 -0500, 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)
.
|
|
|
| User: "" |
|
| Title: Re: Unqualified name lookup doubt (ISO/IEC-14882:2003 3.4.1/13) |
05 Feb 2008 04:01:30 PM |
|
|
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
.
|
|
|
|
|
| User: "=?UTF-8?B?RXJpayBXaWtzdHLDtm0=?=" |
|
| Title: Re: Unqualified name lookup doubt (ISO/IEC-14882:2003 3.4.1/13) |
05 Feb 2008 03:28:29 PM |
|
|
On 2008-02-05 21:28, 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
.
|
|
|
| User: "" |
|
| Title: Re: Unqualified name lookup doubt (ISO/IEC-14882:2003 3.4.1/13) |
05 Feb 2008 04:08:23 PM |
|
|
On Feb 6, 2:28 am, Erik Wikstr=F6m <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
.
|
|
|
|
|

|
Related Articles |
|
|