<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 - Use of std::is_constructible with non-constructible arguments fails with error rather than returning false"
   href="https://bugs.llvm.org/show_bug.cgi?id=40271">40271</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Use of std::is_constructible with non-constructible arguments fails with error rather than returning false
          </td>
        </tr>

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

        <tr>
          <th>Version</th>
          <td>trunk
          </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>Frontend
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>jhoberock@nvidia.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org, neeilans@live.com, richard-llvm@metafoo.co.uk
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Created <span class=""><a href="attachment.cgi?id=21308" name="attach_21308" title="The output of clang -save-temps of the reproducer program.">attachment 21308</a> <a href="attachment.cgi?id=21308&action=edit" title="The output of clang -save-temps of the reproducer program.">[details]</a></span>
The output of clang -save-temps of the reproducer program.

The following program:

#include <type_traits>

template<class T, class Allocator>
struct my_container
{
  my_container(int n, Allocator alloc = Allocator()) {}
};

template<class T>
struct my_not_default_constructible_allocator
{
  // no default ctor
  my_not_default_constructible_allocator(int) {}
};

int main()
{
  bool result = std::is_constructible<my_container<int,
my_not_default_constructible_allocator<int>>, int>::value;

  return 0;
}

Yields a compile time error:

$ clang -std=c++14 repro.cpp 
repro.cpp:6:41: error: no matching constructor for initialization of
'my_not_default_constructible_allocator<int>'
  my_container(int n, Allocator alloc = Allocator()) {}
                                        ^
/usr/bin/../lib/gcc/x86_64-linux-gnu/7.2.0/../../../../include/c++/7.2.0/type_traits:976:24:
note: in instantiation of default function argument expression for
      'my_container<int, my_not_default_constructible_allocator<int> >'
required here
             = decltype(::new _Tp(declval<_Arg>()))>
                              ^
/usr/bin/../lib/gcc/x86_64-linux-gnu/7.2.0/../../../../include/c++/7.2.0/type_traits:977:24:
note: in instantiation of default argument for '__test<my_container<int,
      my_not_default_constructible_allocator<int> >, int>' required here
      static true_type __test(int);
                       ^~~~~~~~~~~
/usr/bin/../lib/gcc/x86_64-linux-gnu/7.2.0/../../../../include/c++/7.2.0/type_traits:987:24:
note: while substituting deduced template arguments into function template
'__test' [with _Tp =
      my_container<int, my_not_default_constructible_allocator<int> >, _Arg =
int, $2 = (no value)]
      typedef decltype(__test<_Tp, _Arg>(0)) type;
                       ^
/usr/bin/../lib/gcc/x86_64-linux-gnu/7.2.0/../../../../include/c++/7.2.0/type_traits:144:14:
note: in instantiation of template class
'std::__is_direct_constructible_impl<my_container<int,
      my_not_default_constructible_allocator<int> >, int>' requested here
    : public conditional<_B1::value, _B2, _B1>::type
             ^
/usr/bin/../lib/gcc/x86_64-linux-gnu/7.2.0/../../../../include/c++/7.2.0/type_traits:992:14:
note: in instantiation of template class
'std::__and_<std::is_destructible<my_container<int,
      my_not_default_constructible_allocator<int> > >,
std::__is_direct_constructible_impl<my_container<int,
my_not_default_constructible_allocator<int> >, int> >' requested here
    : public __and_<is_destructible<_Tp>,
             ^
/usr/bin/../lib/gcc/x86_64-linux-gnu/7.2.0/../../../../include/c++/7.2.0/type_traits:1074:14:
note: in instantiation of template class
'std::__is_direct_constructible_new_safe<my_container<int,
      my_not_default_constructible_allocator<int> >, int>' requested here
    : public conditional<is_reference<_Tp>::value,
             ^
/usr/bin/../lib/gcc/x86_64-linux-gnu/7.2.0/../../../../include/c++/7.2.0/type_traits:1082:14:
note: in instantiation of template class
'std::__is_direct_constructible_new<my_container<int,
      my_not_default_constructible_allocator<int> >, int>' requested here
    : public __is_direct_constructible_new<_Tp, _Arg>::type
             ^
/usr/bin/../lib/gcc/x86_64-linux-gnu/7.2.0/../../../../include/c++/7.2.0/type_traits:1122:14:
note: in instantiation of template class
'std::__is_direct_constructible<my_container<int,
      my_not_default_constructible_allocator<int> >, int>' requested here
    : public __is_direct_constructible<_Tp, _Arg>
             ^
/usr/bin/../lib/gcc/x86_64-linux-gnu/7.2.0/../../../../include/c++/7.2.0/type_traits:1133:14:
note: in instantiation of template class
'std::__is_constructible_impl<my_container<int,
      my_not_default_constructible_allocator<int> >, int>' requested here
    : public __is_constructible_impl<_Tp, _Args...>::type
             ^
repro.cpp:18:22: note: in instantiation of template class
'std::is_constructible<my_container<int,
my_not_default_constructible_allocator<int> >, int>' requested here
  bool result = std::is_constructible<my_container<int,
my_not_default_constructible_allocator<int>>, int>::value;
                     ^
repro.cpp:13:3: note: candidate constructor not viable: requires 1 argument,
but 0 were provided
  my_not_default_constructible_allocator(int) {}
  ^
repro.cpp:10:8: note: candidate constructor (the implicit copy constructor) not
viable: requires 1 argument, but 0 were provided
struct my_not_default_constructible_allocator
       ^
repro.cpp:10:8: note: candidate constructor (the implicit move constructor) not
viable: requires 1 argument, but 0 were provided
1 error generated.


Other compilers accept the input as expected:

$ g++ -std=c++14 repro.cpp 


Compiler details:

$ clang --version ; echo ; g++ --version
clang version 4.0.1-6 (tags/RELEASE_401/final)
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin

g++ (Ubuntu 7.2.0-8ubuntu3.2) 7.2.0
Copyright (C) 2017 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

Stack Overflow discussion:
<a href="https://stackoverflow.com/questions/54099360/why-doesnt-this-use-of-stdis-constructible-compile">https://stackoverflow.com/questions/54099360/why-doesnt-this-use-of-stdis-constructible-compile</a>
Godbolt reproducer: <a href="https://godbolt.org/z/UI5Hy5">https://godbolt.org/z/UI5Hy5</a>

clang -save-temps attached.</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>