Partial specialization with parameter pack behaves differently than manually expanded one
Asked Answered
M

0

6

I'm trying to understand why I'm getting different behavior with 2 templates that should be equivalent to me

Given

template<template<typename...> class TT, typename T1, typename T2>
class A {};

is_a is the generic version

template<typename T>
struct is_a : std::false_type
{
};

template<template<typename...> class TT, typename... T>
struct is_a<A<TT, T...>> : std::true_type
{
};

is_a2 is the version which has been manually expanded to 2 types instead of a paramter pack

template<typename T>
struct is_a2 : std::false_type
{
};

template<template<typename...> class TT, typename T1, typename T2>
struct is_a2<A<TT, T1, T2>> : std::true_type
{
};

I would expect the 2 versions to behave identically when A is instantiated with 3 parameters, but this is not the case

See the code compiling https://wandbox.org/permlink/MjSwFLvWmH0n1QLk

I would expect is_a to work anywhere is_a2 works.

Is this a compiler bug I should report?

EDIT

Apparently this works in clang https://wandbox.org/permlink/9n5pXUGtBa8cAvFw

Mccluskey answered 1/9, 2018 at 15:55 Comment(7)
You don't get this behavior with clang. I'd say that gcc has a bug here, but can't really say for sure.Saiff
Indeed clang works wandbox.org/permlink/9n5pXUGtBa8cAvFw . How can I make sure if it is a compiler bug on GCC side?Mccluskey
You can slightly modify your question to ask about that. I think that would be okay.Saiff
On MSVC it works too godbolt.org/z/Kkbv29. Also it will work on GCC if you change to template<template<typename...> class TT, typename... T> A {};.Villus
Related: core language issue 2328.Hakan
@Mccluskey Report it as a bug to GCC. The developers can mark it "confirmed" if they agree that it's a bug, or explain to you why they think GCC is correct.Backsaw
GCC bug reported: gcc.gnu.org/bugzilla/show_bug.cgi?id=104305Plagal

© 2022 - 2024 — McMap. All rights reserved.