请考虑以下代码:
template<typename T>
struct A { };
// same as A, but with one extra defaulted parameter
template<typename T, typename F = int>
struct B { };
template<template<typename> typename T>
T<int> build() { return {}; }
int main()
{
build<A>(); // works in gcc and clang
build<B>(); // works in gcc, does not work in clang
}
Run Code Online (Sandbox Code Playgroud)
g ++(7.3.0)编译代码就好了,但是,clang ++(5.0.1)会发出以下命令:
example.cpp:14:5: error: no matching function for call to 'build'
build<B>(); // works in gcc, does not work in clang
^~~~~~~~ …Run Code Online (Sandbox Code Playgroud) 下面的代码
#include <cstdint>
template<typename T>
struct allo{};
template <typename T, std::size_t a = alignof(T)>
struct AA{
constexpr std::size_t align() { return a; }
};
template<template <typename> typename AT>
struct SAR{
};
using UHR = SAR<allo>;
using AHR = SAR<AA>;
int main()
{
UHR u;
AHR a;
return 0;
}
Run Code Online (Sandbox Code Playgroud)
被 GCC 使用 接受-std=c++17,但被 GCC 使用std=c++14和 clang 拒绝(无论 C++ 方言如何)。
https://godbolt.org/z/xaE56Y5Pj
哪个编译器是正确的?这是 C++17 中 clang 尚未实现的一些更改吗?