Question: Consider following code snippet:

```
enum class Bar {
    A
};

void foo(Bar) {}

struct Baz {
    void foo() {
        foo(Bar::A);
    }
};

```

It fails to compile, the message from gcc 9.2 is:

```
:12:19: error: no matching function for call to 'Baz::foo(Bar)'
 12 |         foo(Bar::A);
    |              

```

I don't suspect it is a bug since clang 10 also fails. I have two questions regarding this situation:

1. Where does standard define bahaviour for such overloads?
2. What are the possible reasons that compiler behaviour is specified that way?

[live example](https://godbolt.org/z/LcnL9-)

Answer: 
According to the rule of unqualified name lookup, from the standard, [[basic.lookup.unqual]/1](https://timsong-cpp.github.io/cppwp/basic.lookup.unqual#1),

(emphasis mine)

> 
> In all the cases listed in [basic.lookup.unqual], the scopes are searched for a declaration in the order listed in each of the respective categories; **name lookup ends as soon as a declaration is found for the name**.
> 
> 
> 

That means the name `foo` is found at the class scope (i.e. the `Baz::foo` itself), then name lookup stops; the global one won't be found and considered for the overload resolution which happens later.

About your 2nd question, functions can't be overloaded through different scopes; which might cause unnecessary confusion and complexity. Consider the following code:

```
struct Baz {
    void foo(int i) { }
    void foo() {
        foo('A');
    }
};

```

You know `'A'` would be converted to `int` then passed to `foo(int)`, that's fine. If functions are allowed to be overloaded through scopes, if someday a `foo(char)` is added in global scope by someone or library, behavior of the code would change, that's quite confusing especially when you don't know about the adding of the global one.
The call to `foo` inside `Baz::foo()` will only look up names inside the class. If you mean to use the `foo` declared outside the class `Baz`, you need to use the scope-resolution operator, like this:

```
enum class Bar {
    A
};

void foo(Bar) {}

struct Baz {
    void foo() {
        ::foo(Bar::A);   // looks up global 'foo'
    }
};

```

Note that the unscoped call to `foo` fails because there is a `Bar::foo` that is found in the closest scope. If you name the function differently, then no function is found in `Bar`, and the compiler will look in the outer scope for the function. 

```
enum class Bar {
    A
};

void foo(Bar) {}

struct Baz {
    void goo() {   // not 'foo'
        foo(Bar::A);  // this is fine, since there is no 'Bar::foo' to find
    }
};

```

Here's the quote from [cppreference](https://en.cppreference.com/w/cpp/language/unqualified_lookup#Class_definition) for a *class definition*.

> 
> e) if this class is a member of a namespace, or is nested in a class that is a member of a namespace, or is a local class in a function that is a member of a namespace, the scope of the namespace is searched until the definition of the class, enclosing class, or function. if the lookup of for a name introduced by a friend declaration: in this case only the innermost enclosing namespace is considered, otherwise lookup continues to enclosing namespaces until the global scope as usual. 
> 
> 
> 

Of course, this only applies to class definitions, but for *member functions* (which is your example), it says

> 
> For a name used inside a member function body, a default argument of a member function, exception specification of a member function, or a default member initializer, the scopes searched are the same as in [class definition], ...
> 
> 
> 

So the same logic applies.