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

Discussion in 'C++' started by murali.desikan@gmail.com, Feb 5, 2008.

  1. Guest

    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
    , Feb 5, 2008
    #1
    1. Advertising

  2. Pete Becker Guest

    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)
    Pete Becker, Feb 5, 2008
    #2
    1. Advertising

  3. 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
    Erik Wikström, Feb 5, 2008
    #3
  4. Guest

    On Feb 6, 2:27 am, Pete Becker <> 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
    , Feb 5, 2008
    #4
  5. Guest

    On Feb 6, 2:28 am, Erik Wikström <> 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
    , Feb 5, 2008
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Alexei Polkhanov
    Replies:
    11
    Views:
    2,459
  2. Steven T. Hatton
    Replies:
    9
    Views:
    462
    Steven T. Hatton
    Jun 5, 2004
  3. Steven T. Hatton

    Hardcopy of ISO/IEC 14882:2003(E) Quality?

    Steven T. Hatton, Jul 8, 2005, in forum: C++
    Replies:
    0
    Views:
    432
    Steven T. Hatton
    Jul 8, 2005
  4. Alok
    Replies:
    9
    Views:
    1,018
  5. Francois Grieu
    Replies:
    4
    Views:
    526
    Bo Persson
    Feb 8, 2012
Loading...

Share This Page