<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 - clang++ errors when trying to call a constructor that automatically deduces its class template parameters from a Callable -templated class"
   href="https://bugs.llvm.org/show_bug.cgi?id=40183">40183</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>clang++ errors when trying to call a constructor that automatically deduces its class template parameters from a Callable -templated class
          </td>
        </tr>

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

        <tr>
          <th>Version</th>
          <td>7.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>C++'17
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>jacksonmcneillnospam@gmail.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>blitzrakete@gmail.com, erik.pilkington@gmail.com, llvm-bugs@lists.llvm.org, richard-llvm@metafoo.co.uk
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Created <span class=""><a href="attachment.cgi?id=21279" name="attach_21279" title="output of clang, including source, compile commands, and terminal output on crash">attachment 21279</a> <a href="attachment.cgi?id=21279&action=edit" title="output of clang, including source, compile commands, and terminal output on crash">[details]</a></span>
output of clang, including source, compile commands, and terminal output on
crash

clang version 7.0.0-3 (tags/RELEASE_700/final)
Target: x86_64-pc-linux-gnu

This is best described with code. 
/*!
 * Compile with: [g++ or clang++] -std=c++17 bug_code.cpp
 */

//Minimal replacement for std::function to demonstrate bug
template<typename> class callable_templated_class;
template<typename return_t, typename args_t>
class callable_templated_class<return_t(args_t)>
{
        public:
                callable_templated_class()
                {
                }
};


// You can remove one of these and specify int inside the
callable_templated_class<...> callback and still get the error. Removing both
and specifying int on both will not exhibit the error.
template <typename return_t, typename args_t>
class bug_class  
{
        public:
                bug_class(int please_see_comment,
callable_templated_class<return_t(args_t)> callback)
/*!
 *      The 'int' at the beginning of the function is necessary to trigger the
bug in GCC (but not clang). In my testing, it can by any type -- but it must be
present.
 */
                {
                }
};

template <typename return_t, typename args_t>
class no_gcc_bug  
{
        public:
                no_gcc_bug(callable_templated_class<return_t(args_t)> callback)
                {
                }
};


int main()
{
        auto instantiation = callable_templated_class<int(int)>();

        auto this_is_fine_in_gcc = new no_gcc_bug(instantiation); //works in
gcc, does not work in clang(crash)

        auto this_will_error = new bug_class(0,instantiation); //This is a bug
in both GCC and clang. 
        //In GCC: It errors - I don't think it should(check standard?). At the
very least, the error message is wrong/confusing.
        //In Clang: It crashes. 
        return 0;
}


Clang will crash trying to call the constructor for `no_gcc_bug`. I believe
clang is crashing while trying to deduce `return_t` or `args_t` from
`callable_templated_class<return_t(args_t)`. I think this because clang will
not crash if you remove the template from `no_gcc_bug` and use
`callable_templated_class<int(int)>` instead. However, if you keep the template
for `return_t` and/or `args_t`, clang will crash. 

A similar bug exists in GCC, so I will link to the gcc bugzilla post when it's
up. I'm not sure of the correct behavior here, but it shouldn't crash.</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>