Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.std.c++ > #386

Re: Unqualified name lookup

From Francis Glassborow <francis.glassborow@btinternet.com>
Newsgroups comp.std.c++
Subject Re: Unqualified name lookup
Date 2011-12-04 02:23 -0800
Organization unknown
Message-ID <IvOdna6aq6lCxUfTnZ2dnUVZ8oudnZ2d@bt.com> (permalink)
References <f6695839-d821-47f5-a1f6-e87604daa072@w3g2000vbw.googlegroups.com>

Show all headers | View raw


On 03/12/2011 16:24, koszal wrote:
>
> Hello all,
>
> I'm looking for some explanation of the unqualified name lookup
> specified in the spec.
> In particular there is an example in the point 3.4.1$3:
>
> typedef int f;
> namespace N {
>      struct A {
>          friend void f(A&);
>          operator int();
>          void g(A a) {
>              int i = f(a); // f is the typedef, not the friend
>                              // function: equivalent to int(a)
>          }
>      };
> }
>
> and the text below it says:
> [1] "because the expression is not a function call, the argument-
> dependent name lookup (3.4.2) does not apply and the friend function f
> is not found".
>
> Why the expression 'f(a)' is not a function call?  Could somebody
> explain to me how compiler infers here that this is a functional style
> cast and not a function call?
>
> I just can't wrap my head around this - especially if I take into
> account that the note above this example says:
> [2] "For purposes of determining (during parsing) whether an
> expression is a postfix-expression for a function call, the usual name
> lookup rules apply. The rules in 3.4.2 have no effect on the syntactic
> interpretation of an expression."
>
> My reading of this results in the following expectations for this
> particular example:
> 1. var 'i' is initialized by the expression 'f(a)'
> 2. there is an ambiguity since 'f(a)' could be a function style cast
> or a function call
> 3. 'f' should be looked up for what it is and friend function is found
> 4. ambiguity is resolved and this should be treated as a function call
> 5. there is a typing error which should be reported by the user
> Could anybody fix this list for me - most suspected is point 3 but the
> text [1] says that is not a function call so maybe point 2 is also
> wrong?
>
> I'd appreciate any explanations
>
> Best regards
> Andrzej Ostruszka
>
>

It was decided (in order to preserve some important techniques) that a
friend function would not be visible unless
1) the function was declared at namespace scope (i.e. the friend
declaration was insufficient)

or

2) the call was a fully qualified call effectively bringing the class
scope into the search list.

Now in the code above the definition of g() is treated as if it had
been written at namespace scope as:

void A::g(A a){
   int i = f(a);
}

The only f visible at this scope is the typedef and there is nothing
in this relocated code to trigger a search in the scope of A.

I know it seems odd but that is about par for the course when dealing
with name lookup rules :(



--
[ comp.std.c++ is moderated.  To submit articles, try posting with your ]
[ newsreader.  If that fails, use mailto:std-cpp-submit@vandevoorde.com ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html                      ]

Back to comp.std.c++ | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

Unqualified name lookup koszal<krasnal1972@gmail.com> - 2011-12-03 08:24 -0800
  Re: Unqualified name lookup Francis Glassborow <francis.glassborow@btinternet.com> - 2011-12-04 02:23 -0800
    Re: Unqualified name lookup gayan.harutyunyan@googlemail.com - 2012-09-26 17:09 -0700

csiph-web