mardi 20 février 2018

Template template and CRTP: compiler bugs, and GCC and clang do not agree

Consider the following code, in C++11, tested with g++-6, g++-7, clang++-3.8 and clang++-4.0

// Preamble
#include <iostream>

// Base 0
template <class T, template <class, T...> class Derived>
struct base0 {
    void operator=(int) {std::cout << "base0::operator=\n";}
};

// Base 1
template <class T, int N, template <class, T...> class Derived>
struct base1 {
    void operator=(int) {std::cout << "base1::operator=\n";}
};

// Derived 0
template <class T, int N>
struct derived0: base0<int, derived0> {
    using base0::operator=;                     // g++6/7 = SUCCESS, clang++-3.8/4.0 = SUCCESS
    using base0<int, derived0>::operator=;      // g++6/7 = SUCCESS, clang++-3.8/4.0 = ERROR
};

// Derived 1
template <class T, int N>
struct derived1: base1<int, N, derived1> {
    using base1::operator=;                     // g++6/7 = ERROR, clang++-3.8/4.0 = ERROR
    using base1<int, N, derived1>::operator=;   // g++6/7 = SUCCESS, clang++-3.8/4.0 = ERROR
};

// Main
int main()
{
    derived0<int, 3> object0;
    derived1<int, 3> object1;
    object0 = 42;
    object1 = 42;
    return 0;
}

g++ and clang++ do not produce errors with the same version of the using base::operator=. Which one of them is right, and what does the C++ standard say?

Aucun commentaire:

Enregistrer un commentaire