相关疑难解决方法(0)

ADL在constexpr函数中不起作用(仅适用于clang)

以下代码使用MSVC和gcc进行编译,但不能使用clang进行编译。为什么?

如果CallFoo ()is的话,似乎ADL无法正常工作constexpr。查看评论。

template <class T>
constexpr void CallFoo  ()          // Remove constexpr to fix clang compilation error.
{
    Foo (T ());
}


class Apple {};


int main ()
{
    CallFoo<Apple> ();
}


constexpr void Foo (Apple)
{
}
Run Code Online (Sandbox Code Playgroud)

Clang错误消息(请参阅godbolt.org):

<source>:4:5: error: use of undeclared identifier 'Foo'
    Foo (T ());
    ^
<source>:13:5: note: in instantiation of function template specialization 'CallFoo<Apple>' requested here
    CallFoo<Apple> ();
    ^
Run Code Online (Sandbox Code Playgroud)

c++ templates clang argument-dependent-lookup constexpr

7
推荐指数
1
解决办法
92
查看次数