【发布时间】:2018-10-24 08:59:25
【问题描述】:
以下程序是为了滥用 gcc/msvc 中两阶段查找的一些特性而构建的。它可以与 gcc/msvc 和 clang 一起编译,但会导致函数 g 的返回值不同:
struct A;
struct C {};
struct D {
D (const A &);
};
struct B {
void f (const C&,int){x=0;};
void f (const D&,char){x=1;};
int x;
};
template<typename T>
int f(const A &y)
{
B x;
x.f(y,0); // Line 18
return x.x;
}
struct A
{
operator C () const;
};
int g (const A&x)
{
return f<int>(x);
}
https://gcc.godbolt.org/z/pqAVsU
GCC 和 MSVC 都调用 A::operator C 并返回 0,而 Clang 调用 D(const A &) 并返回 1。
根据标准,clang 是正确的并且在 struct A 尚未声明时应该解决第 18 行的调用是否正确,或者这是未指定行为的情况?
【问题讨论】:
-
@Predelnik 有些人比其他人更容易触发,但一旦问题得到解决,表现得更好的人就会挂起 DV。
-
@Quentin 好的。感谢您的编辑。我删除了我的评论,因为它当时很火爆。
-
哦,我明白了,问题的关键部分仍然只在链接的 Godbolt 输出中可见...
-
我在这里没有看到名称查找问题。
标签: c++ language-lawyer name-lookup