PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > comp.lang.cplus > Unqualified name lookup doubt (ISO/IEC-14882:2003 3.4.1/13)
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
Unqualified name lookup doubt (ISO/IEC-14882:2003 3.4.1/13)

Réponse
 
LinkBack Outils de la discussion
Vieux 05/02/2008, 20h28   #1
murali.desikan@gmail.com
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut 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
  Réponse avec citation
Vieux 05/02/2008, 21h27   #2
Pete Becker
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Unqualified name lookup doubt (ISO/IEC-14882:2003 3.4.1/13)

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)


  Réponse avec citation
Vieux 05/02/2008, 21h28   #3
Erik Wikström
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Unqualified name lookup doubt (ISO/IEC-14882:2003 3.4.1/13)

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
  Réponse avec citation
Vieux 05/02/2008, 22h01   #4
murali.desikan@gmail.com
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Unqualified name lookup doubt (ISO/IEC-14882:2003 3.4.1/13)

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
  Réponse avec citation
Vieux 05/02/2008, 22h08   #5
murali.desikan@gmail.com
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Unqualified name lookup doubt (ISO/IEC-14882:2003 3.4.1/13)

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
  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 14h13.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,12521 seconds with 13 queries