6

I have a question that seems to be about template template arguments. Following code (life code on GodBolt.org) compiles with GCC up to 11.2, but it does not compiles with Clang++ up to 13.0.1.

The problem seems to lie in the last two lines of the code.

What I try to achieve is to remember the template template parameter passed to HullWrapper as a alias template in HullWrapper so that it can be re-used afterwards.

Especially in the second to last line, I would like to re-built the base template that the class HullClass is derived from. I try this by specializing the HullWrapper template with the template argument remembered via the alias template.

Unfortunately this does not work in Clang++. It does in G++, however. It seems, that for Clang++ a HullWrapper<Hull> is not the same as HullWrapper<HullClass::HullType> although HullType is an alias template to template parameter T which got Hull passed into it.

#include <type_traits>

template <typename T> struct Hull {};

template <template <typename> class T>
struct HullWrapper
{
  template <typename U> using HullType = T<U>;
};


struct HullClass : HullWrapper<Hull> {};


HullClass hullObj;
HullWrapper<Hull>* hullWrapperPtr2 = &hullObj;
HullClass* hullPtr =  &hullObj;

// Following two lines does not compile with Clang++
HullWrapper<HullClass::HullType>* hullWrapperPtr1 = &hullObj;
static_assert(std::is_same<HullWrapper<Hull>, HullWrapper<HullClass::HullType>>::value, "OUCH!");

Now I would like to ask, who is right here? I would think G++, as I am thinking a alias template is an alias to another template the same as a type-alias is an alias to another type.

Could someone enlight me and provide me some insight?

Thanks in advance for your help ...

chi
  • 309
  • 1
  • 4
  • Even if we take `HullClass` out of the picture `static_assert(std::is_same, HullWrapper::HullType>>::value, "OUCH!");` fails too as well as `HullWrapper::HullType>* hullWrapperPtr1 = &hullObj;` So it isn't something with inheritance – Botond Horváth Feb 16 '22 at 09:52
  • Aliasing type are real aliases. For template template, it is more complex, and I think there are also differences between standard version... – Jarod42 Feb 16 '22 at 10:15
  • 2
    Related to [equality-of-template-aliases](https://stackoverflow.com/questions/56010651/equality-of-template-aliases). – Jarod42 Feb 16 '22 at 10:16

0 Answers0