相关疑难解决方法(0)

在clang中显式指定的参数无效但在gcc中成功编译 - 谁错了?

以下代码在g ++中编译时没有问题:

#include <iostream>
#include <string>
#include <tuple>

template<typename T>
void test(const T& value)
{
    std::tuple<int, double> x;
    std::cout << std::get<value>(x);
}

int main() {
    test(std::integral_constant<std::size_t,1>());
}
Run Code Online (Sandbox Code Playgroud)

我使用了这个命令:

g++ test.cpp -o test -std=c++14 -pedantic -Wall -Wextra
Run Code Online (Sandbox Code Playgroud)

但是当我切换g++clang++(使用g ++ 5.1.0和clang ++ 3.6.0)时,我收到以下错误:

test.cpp:9:18: error: no matching function for call to 'get'
    std::cout << std::get<value>(x);
                 ^~~~~~~~~~~~~~~
test.cpp:13:5: note: in instantiation of function template specialization 'test<std::integral_constant<unsigned long, 1> >' requested here
    test(std::integral_constant<std::size_t,1>());
         ^~~~~~~~~~~~~~~
<skipped>

/usr/bin/../lib/gcc/x86_64-linux-gnu/5.1.0/../../../../include/c++/5.1.0/tuple:867:5: note: candidate template ignored: …
Run Code Online (Sandbox Code Playgroud)

c++ gcc templates clang

8
推荐指数
1
解决办法
5066
查看次数

标签 统计

c++ ×1

clang ×1

gcc ×1

templates ×1