<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - Erroneous template deduction"
   href="https://bugs.llvm.org/show_bug.cgi?id=49520">49520</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Erroneous template deduction
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>clang
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>unspecified
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>Linux
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>normal
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>C++
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedclangbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>ColinMacLean@lbl.gov
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>blitzrakete@gmail.com, dgregor@apple.com, erik.pilkington@gmail.com, llvm-bugs@lists.llvm.org, richard-llvm@metafoo.co.uk
          </td>
        </tr></table>
      <p>
        <div>
        <pre>I discovered a bug in Clang's template argument deduction while working on
array support for a pointer wrapping class. This incorrect behavior can be
simplified into the following reproducer:

#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) {}

void test()
{
    int * t1;
    A<int> t2;
    A<int[]> t3;
    foo(t1,t2);
    foo(t1,t3); // GCC: correctly errors on conflicting deductions for T: int
and int[]
                // Clang: Erroneously performs implicit cast, which should only
be allowed 
                //        after a successful template deduction
    bar(t1,t2);
    bar(t1,t3); // Compliant implicit cast for second argument.
}

In the case of the function foo(), the deduction should try to deduce to both
int and int[] simultaneously with the parameters t1 and t3 and fail due to
being different types. Godbolt shows T is deduced to int on Clang.
std::type_identity_t<T> should be necessary to establish a non-deduced context
if implicit conversion to A<int> is desired. This implicit conversion should
only happen after a template deduction is successful.

This bug affects all known Clang versions, tested from 3.0 to trunk with
Godbolt. It also affects all C++ standard options used from C++98 to C++2a.</pre>
        </div>
      </p>


      <hr>
      <span>You are receiving this mail because:</span>

      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>