【发布时间】:2017-08-16 12:33:20
【问题描述】:
#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;
}
为什么 memcpy 在这里是模棱两可的称呼?
请查看 ANSI ISO IEC 14882、C++2003、3.4.1、(6)(第 30 页)中变量“i”的示例。它“证明”了这种结构没有歧义。
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
}
不合格的查找规则是否在 GCC 中被破坏或者我没有理解某些内容?
【问题讨论】:
-
您能否将 C++2003, p.30 中的示例包括在内。 3.4.1, (6) ?
-
最好把例子贴在这里。
-
如果您希望我们参考语言标准的某些特定部分,如果您引用该标准的相关部分会更有帮助。跨度>
-
我看不出你的代码和例子有什么相似之处。
-
@tobi303 附加示例
标签: c++ g++ language-lawyer name-lookup