4

Consider this function call:

foo::bar();

11.3.1.1.1, paragraph 3 [over.call.func] (N4778) covers this case:

In unqualified function calls, the name is not qualified by an -> or . operator and has the more general form of a primary-expression. The name is looked up in the context of the function call following the normal rules for name lookup in function calls...

Here, foo::bar is an unqualified name, in the sense that it's not qualified by -> or .. So this paragraph applies. Now, the meaning of the phrase "looked up in the context of" is explained in 6.4, paragraph 2 [basic.lookup]:

A name “looked up in the context of an expression” is looked up as an unqualified name in the scope where the expression is found.

However, foo::bar is a qualified name in the realm of name lookup. In other words, this combination of paragraphs basically say that, the qualified name foo::bar is looked up by the rule of unqualified name lookup. However, I don't think that unqualified name lookup is capable of recursively entering into a narrower scope, i.e., foo to bar. Is this a defect?

curiousguy
  • 8,038
  • 2
  • 40
  • 58
  • 2
    just curious, why which rules used during lookups would be the matter of any interest? surely there has to be a reason if they included in the document. – Yucel_K Oct 19 '18 at 09:53
  • 1
    `foo::bar()` can still be in another namespace. – Jarod42 Oct 19 '18 at 09:55
  • @Yucel_K This might be a defect in the document, and that's why I'm asking this here. – eca2ed291a2f572f66f4a5fcf57511 Oct 19 '18 at 10:05
  • @Jarod42 Can you elaborate more? I'm not sure how your comment is related to my question. – eca2ed291a2f572f66f4a5fcf57511 Oct 19 '18 at 10:05
  • 2
    Not sure by comment is valid though, but `foo::bar` might refer to `N::foo::bar` and not `::foo::bar`. (thanks to `using`, whereas `c.bar()` cannot refer to another `namespace`). – Jarod42 Oct 19 '18 at 10:30
  • @Jarod42 Well, resolving the qualified name `foo::bar` must involve qualified name lookup, not unqualified name lookup. This is true since unqualified name lookup keeps searching **outward** while qualified name lookup does this **inward**. As you can see that this question is tagged under `language-lawyer`, my question was to see if anyone agrees that the standard made a mistake as to mis-tagging this specific case as an example of unqualified name lookup. I think that this is a defect. – eca2ed291a2f572f66f4a5fcf57511 Oct 19 '18 at 11:55
  • @9room Resolving `foo::bar` implies "resolving `foo`" which involves unqualified name lookup. – curiousguy Nov 07 '18 at 00:12

1 Answers1

1

No, I don't think this is a defect. It says

The name is looked up in the context of the function call following the normal rules for name lookup in function calls [...]

As you can see from the part that I highlighted, the standard specifies how the name is supposed to be looked up: By name lookup.

Name lookup involves unqualified, qualified and argument-dependent lookup, so your name is indeed resolved by the qualified name lookup rules.

The "looked up in the context of expr" rule doesn't apply here, as it is specified what rule is used. That paragraph only comes into play when it's not. For example, in [class.qual]p1:

the names in a template-argument of a template-id are looked up in the context in which the entire postfix-expression occurs.

Rakete1111
  • 47,013
  • 16
  • 123
  • 162
  • For future viewers, note that the phrase _looked up in the context of_ in these paragraphs doesn't seem to carry a special meaning with it. IMO, the explicit reference to 6.4 (which I omitted in the above quote) overrides any ambiguity there so that the entire name lookup shall take place, which also includes qualified name lookup. – eca2ed291a2f572f66f4a5fcf57511 Oct 24 '18 at 13:21