Unqualified name lookup doubt (ISO/IEC-14882:2003 3.4.1/13)

M

murali.desikan

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
 
P

Pete Becker

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
}
 
E

Erik Wikström

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;
}
 
M

murali.desikan

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
 
M

murali.desikan

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top