<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 - Compiler is using wrong template argument when a child class calls a templated constructor of a template class."
   href="https://bugs.llvm.org/show_bug.cgi?id=48365">48365</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Compiler is using wrong template argument when a child class calls a templated constructor of a template class.
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>libc++
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>11.0
          </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>enhancement
          </td>
        </tr>

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

        <tr>
          <th>Component</th>
          <td>All Bugs
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>nicolas.brun@gmail.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org, mclow.lists@gmail.com
          </td>
        </tr></table>
      <p>
        <div>
        <pre>The following code doesn't compile correctly:

<<
#include <type_traits>

template <typename Type>
struct CheckInt {
  using success = std::bool_constant<std::is_same_v<Type, float>>;
  static_assert(success());
};

template <typename T>
class Base {
  public:
    template <typename U, typename = typename CheckInt<U>::success>
    Base(const U& v) {}
};

class Child : public Base<int> {
  public:
    Child() : Base(1.0f) {}
};

int main()
{
  Child child; // doesn't compile
  //Base<int> base(1.0f); // compiles

  return 0;
}
<span class="quote">>></span >

When instantiating Child, the static_assert() fires because U evaluates to
`Base<int>` instead of `float`.
When instantiation Base<int> directly, U evaluates  to `float` correctly.

The compiler generates the following error:
"
<source>:6:3: error: static_assert failed due to requirement
'std::integral_constant<bool, false>()'
  static_assert(success());
  ^             ~~~~~~~~~
<source>:12:47: note: in instantiation of template class 'CheckInt<Base<int>>'
requested here
    template <typename U, typename = typename CheckInt<U>::success>
"

The bug appears in all versions of clang (as well as gcc).

See <a href="https://godbolt.org/z/73c4Wd">https://godbolt.org/z/73c4Wd</a></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>