C++ Logo


Advanced search

Compiler disagreement and [temp.deduct.call]/4.3

From: Colin MacLean <ColinMacLean_at_[hidden]>
Date: Thu, 9 Dec 2021 22:33:48 -0800
Hi everyone,

I've come across the following compiler disagreement when it comes to the
interpretation of [temp.deduct.call]/4.3

#include <type_traits>

template<typename T>
struct A {};

template<typename T>
struct A<T[]> : A<T> {};

template<typename T>
void foo(T* a, A<T>& b) {}

template<typename T>
void bar(T* a, A<std::type_identity_t<T>>& b) {}

int main()
    int * t1;
    A<int> t2;
    A<int[]> t3;
    foo(t1,t2); // works as expected
    foo(t1,t3); // Clang: foo(int*, A<int>&)
                // Intel: foo(int*, A<int>&)
                // GCC: deduced conflicting types for T
                // MSVC: deduced conflicting types for T
    bar(t1,t2); // works as expected
    bar(t1,t3); // bar(int*, A<int>&). Works as expected due to
type_identity making dependent type
    return 0;

Godbolt link: https://godbolt.org/z/Wh4ME7bv9.

I believe GCC and MSVC are correct in rejecting foo(t1,t3) and that
type_identity should be required to form a dependent type to avoid
ambiguity in the deduction of T.


Received on 2021-12-10 00:34:02