4

Foot note (33) in page 53 of N4140:

Lookups in which function names are ignored include names appearing in a nested-name-specifier, an elaborated-type-specifier, or a base-specifier.

Columbo
  • 60,038
  • 8
  • 155
  • 203
Ayrosa
  • 3,385
  • 1
  • 18
  • 29

1 Answers1

7
namespace A
{
    void std();
    void foo()
    {
        std::cout << "Hello World"; // (1)
    }
};

In (1), std cannot name a function, thus the function A::std is ignored during lookup, and the code compiles.
This rule is explicitly mentioned in [basic.lookup.qual]/1:

If a :: scope resolution operator in a nested-name-specifier is not preceded by a decltype-specifier, lookup of the name preceding that :: considers only namespaces, types, and templates whose specializations are types.

Another example from the list includes

class A : B {};

Here, B cannot designate a function, thus any functions called B are ignored during lookup. Same goes for

class A a;

Where A cannot name a function.

Columbo
  • 60,038
  • 8
  • 155
  • 203
  • How an expression like `std::chrono::high_resolution_clock` would find a function named `chrono`? Shouldn't the name to be found be located **after** the last `::` in the *nested-name-specifier*? – Ayrosa Jan 29 '15 at 17:17
  • 1
    @Ayrosa I think you're a little bit confused. The nested-name-specifier is the bit before the last identifier, in this case `std::chrono::`. `chrono` must be found by lookup just as `high_resolution_clock` must be. Every name must be looked up, including `std` and `chrono`. – Columbo Jan 29 '15 at 17:28
  • To be fair though, there cannot be a `std::chrono` function anyway, because you cannot have a function and a namespace with the same name in the same parent namespace. Perhaps `#include ` / `namespace N { void std(); int zero() { return std::move(0); } } int main() { return N::zero(); }` makes for a good example? –  Jan 29 '15 at 17:33
  • 1
    @Columbo I think I finally understood your example. Even though `std()` is a member function of `A`, the code doesn't break in (1) because the name of the function `std` is ignored by the lookup for the name `std` started at the expression `std::cout << ...`.Is that correct? – Ayrosa Jan 29 '15 at 18:01