Quantcast
Channel: Active questions tagged gcc - Stack Overflow
Viewing all articles
Browse latest Browse all 22057

Why does clang handle exceptions for this trivial std::variant code?

$
0
0

If we have code like this:

#include <variant>int main(){    using V = std::variant<int, double>;    V a = 5;    V b = 5.6;    a.swap(b);}

https://gcc.godbolt.org/z/oqGiHs

If you compile with clang, it emits code that handle exception during swap.

Why is that? Both variants are non empty and underlying types are exception safe.

Update:

Ironically this compiles without exception:

#include <variant>template<class T>void sw(T &a, T &b){    auto c = a;    a = b;    b = c;}int main(){    using V = std::variant<int, double>;    V a = 5;    V b = 5.6;    sw(a, b);}

Viewing all articles
Browse latest Browse all 22057

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>