0

I'm trying to compare two template template parameters of which one is aliased. It seems to work with the GCC compiler but unfortunately it doesn't with Clang.

The meta-function to compare the template template parameters can be considered rather naive but it fulfills my current needs. The pitfalls are being unable to compare template template parameters which contain non-type template arguments or a mix between types and non-types.

I've found a couple of similar questions which can be found here, here, and here. The underlying issue is likely related in some way but the suggested workarounds are either inapplicable or ineffective.

#include <type_traits>

template<template<typename...> typename, template<typename...> typename>
struct is_same_tpl : std::false_type {};

template<template<typename...> typename T>
struct is_same_tpl<T, T> : std::true_type {};

template<typename T>
struct x {};

template<typename>
struct w;

template<>
struct w<bool> {
    template<typename T>
    using type = x<T>;
};

static_assert(is_same_tpl<x, x>{});
static_assert(is_same_tpl<w, w>{});
static_assert(is_same_tpl<w<bool>::type, w<bool>::type>{});

static_assert(not is_same_tpl<x, w>{});
static_assert(not is_same_tpl<w, w<bool>::type>{});

static_assert(is_same_tpl<x, w<bool>::type>{});             // fails with Clang
static_assert(is_same_tpl<x, w<bool>::template type>{});    // fails with Clang
static_assert(std::is_same_v<x<int>, w<bool>::type<int>>);

auto main() -> int {}

Live example

  1. Is this a compiler bug in Clang that is yet to be fixed?
  2. Is there a workaround for Clang that can make the static assertions succeed?
303
  • 1,201
  • 1
  • 7
  • 20

0 Answers0