[llvm-bugs] [Bug 38801] New: Throwing exception uses incorrect copy constructor

via llvm-bugs llvm-bugs at lists.llvm.org
Sat Sep 1 02:23:49 PDT 2018


https://bugs.llvm.org/show_bug.cgi?id=38801

            Bug ID: 38801
           Summary: Throwing exception uses incorrect copy constructor
           Product: clang
           Version: 7.0
          Hardware: PC
                OS: Windows NT
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: -New Bugs
          Assignee: unassignedclangbugs at nondot.org
          Reporter: jvapen at gmail.com
                CC: llvm-bugs at lists.llvm.org

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.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20180901/3489bd6d/attachment-0001.html>


More information about the llvm-bugs mailing list