martinmoene / span-lite

span lite - A C++20-like span for C++98, C++11 and later in a single-file header-only library
Boost Software License 1.0
495 stars 40 forks source link

tuple_element is declared as a struct but in the standard library headers it's a class #50

Closed vlovich closed 4 years ago

vlovich commented 4 years ago

This results in a compilation warning. https://en.cppreference.com/w/cpp/utility/tuple/tuple_element lists it as a class too. Needs to be changed to class + the forward-declaration in non-C++11 mode.

martinmoene commented 4 years ago

C++14 and C++20 drafts show this:

// 23.4.4, tuple-like access to pair
template<size_t I, class T> class tuple_element;
template<size_t I, class T1, class T2> struct tuple_element<I, pair<T1, T2>>;

Is it allowed for a template specialization to be struct whereas the base template is class, or would that be an editorial mistake?

vlovich commented 4 years ago

Same problem appears for tuple_size btw but this does appear to vary by toolchain. libstdc++ & MSVC use struct, libc++ uses class. Unless you want to support arbitrary versions, I think #pragma GCC system_header and #pragma clang system_header directives might be useful to aid integration rather than trying to match class/struct.

vlovich commented 4 years ago

Perhaps adding -Wall to your build might help surface some of these integration issues?

martinmoene commented 4 years ago

As far as i can see, only clang produces this warning and "AFAICS, this warning is wrong and the clang developers should remove it."

So I'm inclined to add -Wno-mismatched-tags to ~the build~ span.hpp.

martinmoene commented 4 years ago

@vlovich Can I close this issue?

vlovich commented 4 years ago

Yup