I'm playing with the C++17 std::variant type and tried to compile the cppreference example code for get()
:
#include <variant>
#include <string>
int main()
{
std::variant<int, float> v{12}, w;
int i = std::get<int>(v);
w = std::get<int>(v);
w = std::get<0>(v); // same effect as the previous line
// std::get<double>(v); // error: no double in [int, float]
// std::get<3>(v); // error: valid index values are 0 and 1
try {
std::get<float>(w); // w contains int, not float: will throw
}
catch (std::bad_variant_access&) {}
}
in XCode 10. My project is set to C++17, but I get compiler errors:
Call to unavailable function 'get': introduced in macOS 10.14
and
'bad_variant_access' is unavailable: introduced in macOS 10.14
which is surprising in 2 ways: it should compile if std::variant
is supported and the hint about macOS 10.14 is weird, given that I'm on that version and it has nothing to do with the supported C++ dialect (and the project's deployment target is 10.14).
Is this something I'm doing wrong or a bug in clang?