Unqualified lookup in C++

Viewed 809
#include <stdio.h>
#include <cstddef>
#include <cstring>

namespace /*namespace name generated by compiler*/
{
    struct BB{};
}

struct AA{};

namespace my
{
    inline void * memcpy(void*, const void*, std::size_t)
    {
        puts("CUSTOM IMPLEMENTATION");
        return 0;
    }
}

namespace my
{
    void func()
    {
        AA a;
        memcpy(&a, &a, sizeof(a)); // ambigious call for g++4.7 - g++6.2

        BB b;
        memcpy(&b, &b, sizeof(b)); // unambigious call

    }
}

int main(int, char **)
{
    my::func();
    return 0;
}

Why memcpy is ambigious call here?

Please take a look at example with variable "i" in ANSI ISO IEC 14882, C++2003, 3.4.1, (6) (page 30). It "proves" that there is no ambigioty in such construction.

namespace A {
  namespace N {
    void f();
  }
}
void A::N::f() {
    i = 5;
// The following scopes are searched for a declaration of i:
// 1) outermost block scope of A::N::f, before the use of i
// 2) scope of namespace N
// 3) scope of namespace A
// 4) global scope, before the definition of A::N::f
}

Is unqualified lookup rules was broken in GCC or I did not understand something?

1 Answers
Related