Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Throwing exception uses incorrect copy constructor #38149

Open
JVApen opened this issue Sep 1, 2018 · 6 comments
Open

Throwing exception uses incorrect copy constructor #38149

JVApen opened this issue Sep 1, 2018 · 6 comments
Labels
bugzilla Issues migrated from bugzilla c++ clang:frontend Language frontend issues, e.g. anything involving "Sema" confirmed Verified by a second party platform:windows

Comments

@JVApen
Copy link

JVApen commented Sep 1, 2018

Bugzilla Link 38801
Version 7.0
OS Windows NT
CC @zmodem,@JVApen

Extended Description

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.
@JVApen
Copy link
Author

JVApen commented Sep 1, 2018

Question: Any chance the fix can still be part of LLVM 7.0.0?

@JVApen
Copy link
Author

JVApen commented May 2, 2019

Correcting 'enhancement' to 'normal' issue. This ain't a feature request.

@zmodem
Copy link
Collaborator

zmodem commented Feb 25, 2020

This does not seem to be getting fixed for clang 10, and I don't think we can block on it.

@llvmbot llvmbot transferred this issue from llvm/llvm-bugzilla-archive Dec 10, 2021
@AaronBallman AaronBallman added c++ clang:frontend Language frontend issues, e.g. anything involving "Sema" confirmed Verified by a second party platform:windows and removed clang Clang issues not falling into any other category labels Jun 18, 2023
@llvmbot
Copy link
Member

llvmbot commented Jun 18, 2023

@llvm/issue-subscribers-clang-frontend

@llvmbot
Copy link
Member

llvmbot commented Jun 18, 2023

@llvm/issue-subscribers-c-1

@AaronBallman
Copy link
Collaborator

This issue reproduces in Clang 16.0.0, only for Win32 targets, and it does not match the behavior of MSVC: https://godbolt.org/z/KsbfPE74q

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugzilla Issues migrated from bugzilla c++ clang:frontend Language frontend issues, e.g. anything involving "Sema" confirmed Verified by a second party platform:windows
Projects
None yet
Development

No branches or pull requests

4 participants