<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 - Throwing exception uses incorrect copy constructor"
   href="https://bugs.llvm.org/show_bug.cgi?id=38801">38801</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Throwing exception uses incorrect copy constructor
          </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>Windows NT
          </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>-New Bugs
          </td>
        </tr>

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

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

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Hello all,

The following code seems to have problems being executed.
It looks like when throwing an exception, Clang tries to use a copy constructor
for the exception, however, instead of using the const& variant, it searches
for a variant without the const.
So instead of using the Copy constructor, it uses the variadic Ctor, which is
not as expected.

test.cpp
--------

struct A
{
   template<typename ... T>
   A(T &&...t)
   {
      static_assert(sizeof...(T) == 2);
   }

   A(const A &) = default;
   //A(A &) = default;
   A(A &&) = default;
   A &operator=(const A &) = default;
   A &operator=(A &&) = default;
};


int main(int, char **)
{
   throw A{size_t{}, size_t{}};
   return 0;
}


run.bat
-------
clang-cl.exe -fms-compatibility-version=19.11 /DBOOST_USE_WINDOWS_H -w
-Wno-unused-command-line-argument /Zc:inline /nologo /c /GR /EHsc /fp:precise
/FS /std:c++17 /diagnostics:caret /O2 /I. /MDd /Zc:forScope /bigobj /Zc:wchar_t
test.cpp


error
-----
test.cpp(7,7):  error: static_assert failed
      static_assert(sizeof...(T) == 2);
      ^             ~~~~~~~~~~~~~~~~~
test.cpp(20,10):  note: in instantiation of function template specialization
'A::A<A &>' requested here
   throw A{size_t{}, size_t{}};
         ^
1 error generated.</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>