samedi 25 avril 2015

Constexpr is not allowed in declaration of friend template specialization?

I'm porting a C++14-constexpr codebase from Clang to the latest g++-5.1. Consider the following reduced code snippet of a home-grown bitset class that has been compiling correctly since the halcyon days of Clang 3.3 (almost 2 years now!)

#include <cstddef>

template<std::size_t>
class bitset;

template<std::size_t N>
constexpr bool operator==(const bitset<N>& lhs, const bitset<N>& rhs) noexcept;

template<std::size_t N>
class bitset
{
    friend constexpr bool operator== <>(const bitset<N>&, const bitset<N>&) noexcept;
    //^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ <-- error from this piece
};

template<std::size_t N>
constexpr bool operator==(const bitset<N>& /* lhs */, const bitset<N>& /* rhs */) noexcept
{
    return true;
}

int main() {}

Live example on Wandbox. However, g++-5.1 and the current trunk release give an error:

'constexpr' is not allowed in declaration of friend template specialization

Question: is this a known g++ bug or is Clang not conforming to the latest Standard?

Note: the above only uses C++11 style constexpr features, since there are no modifications taking place inside operator==, so it seems some weird interference between templates, friends and constexpr.

Aucun commentaire:

Enregistrer un commentaire