9

I successfully compile the SSCCE code snippet below in Clang 8.0.0, MSVC v19.20 and GCC 8.3. Both MSVC and Clang will make the program return 0 and GCC causes the program to return 1 (godbolt), so there is a difference and I don't know which compiler produces the correct output.

#include <type_traits>

template<typename T>
struct Foo {
    template <typename U>
    using inner = Foo<U>;
};

template<template<typename ...Ts> typename>
struct is_foo_template : std::false_type {};
template<>
struct is_foo_template<Foo> : std::true_type {};

template<typename T>
struct is_foo : is_foo_template<T::template inner> {};

int main() {
    return is_foo<Foo<int>>::value;
}

I think that this snippet returns is_foo<Foo<Int>>::value, but the value is either std::true_type::value or std::false_type::value depending on if the Foo-specialization of is_foo_template is selected or not. But the value returned from main is not the same for all three compilers mentioned above, so it seems to me that not all compilers selects the same specialization.

Question(s): According to the standard, should the Foo-specialization be selected or should non-specialized template declaration be selected?

Jesper Juhl
  • 30,449
  • 3
  • 47
  • 70
Joakim Thorén
  • 1,111
  • 10
  • 17
  • An interesting question. Just curious what would be the type `inner` for `Foo`? – vahancho Apr 15 '19 at 12:35
  • I think it's a GCC bug. In some cases it's obvious that `template <...> using` creates a new type template (e.g. `template using X = int;` can be passed to `template typename` template parameter), so I assume it creates a new type template in *all* cases. – HolyBlackCat Apr 15 '19 at 12:36
  • @vahancho It would be an [alias template](https://en.cppreference.com/w/cpp/language/type_alias), so its a family of types (not a single type). You can use the alias template to create a type, like so: `Foo::inner`, which is just `Foo` and has nothing to do with the `typename T=int` template parameter afaik. – Joakim Thorén Apr 15 '19 at 13:01
  • 4
    [CWG1286](https://wg21.link/cwg1286) – cpplearner Apr 15 '19 at 13:40

0 Answers0