Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
throwing std::function on MSVC is dangerous
//Microsoft (R) C/C++ Optimizing Compiler Version 19.00.23506 for x64 #include <stdexcept> #include <exception> #include <stdio.h> #include <functional> struct Int { std::function<int()> f_; explicit Int(int i) : f_([i]() { return i; }) {} explicit operator int() const { return f_(); } Int(Int&& x) : Int(int(x)) { puts("Int is being move-constructed"); } Int(const Int&) = delete; Int& operator=(const Int&) = delete; Int& operator=(Int&&) = delete; ~Int() { puts("Int is being destroyed"); } }; using T = Int; int main() { try { throw T(42); } catch (T& i) { printf("&i = %p (%d)\n", &i, int(i)); fflush(stdout); try { throw; } catch (T& i) { printf("after throw; &i = %p (%d)\n", &i, int(i)); fflush(stdout); try { throw; } catch (T& i) { printf("after throw; &i = %p (%d)\n", &i, int(i)); fflush(stdout); try { auto ex = std::current_exception(); std::rethrow_exception(ex); } catch (T& i) { printf("after exception_ptr; &i = %p (%d)\n", &i, int(i)); fflush(stdout); try { auto ex = std::current_exception(); std::rethrow_exception(ex); } catch (T& i) { printf("after exception_ptr; &i = %p (%d)\n", &i, int(i)); fflush(stdout); } } } } } }
run
|
edit
|
history
|
help
0
Structured Member Value Access Using Structure Member Pointer and Variadic Templates
algorithm_1
Regex pipe and tabs c++
ordinary queue
Guess a number in c++
Removing __unaligned specifier partial solution
Sum of numbers in a series using sum formular
jkljklj
problem_solution5
hangman