The following program attempts to provide a specialization for std::tuple_element
for the user-defined type foo
. Unfortunately, clang-3.5
rejects it with libc++, but using other compilers or using other standard libraries with clang-3.5
accept the program. Is it correct? If no, why not?
#include <utility>
struct foo {};
namespace std
{
template<size_t, class> struct tuple_element;
template<size_t i>
struct tuple_element<i, foo> {};
}
int main()
{
return 0;
}
Compiler output:
$ clang-3.5 -std=c++11 -stdlib=libc++ -lc++ test.cpp
test.cpp:11:8: error: explicit specialization of non-template struct 'tuple_element'
struct tuple_element<i, foo> {};
^ ~~~~~~~~
1 error generated.
$ clang-3.5 -std=c++11 -lstdc++ test.cpp
(no error)
$ g++-4.9 -std=c++11 test.cpp
(no error)
struct
withclass
fixes a warning as well. Also note that the forward declaration makes the program ill-formed, as you are free to specialize types instd
, but any declaration is verboten (even a forward declaration!). The build break is compliant. – Cupreous