diff options
author | Eric Fiselier <eric@efcs.ca> | 2019-07-14 18:21:15 +0000 |
---|---|---|
committer | Eric Fiselier <eric@efcs.ca> | 2019-07-14 18:21:15 +0000 |
commit | 194b337f3327691ee88007061c71225c934b3af0 (patch) | |
tree | ab6e8e7224881de0e09d93c23f7321ff83776ece /libcxx/test/std/utilities | |
parent | 57190b3974fbc07cdb5b61aeaf023de94c2afe7e (diff) | |
download | bcm5719-llvm-194b337f3327691ee88007061c71225c934b3af0.tar.gz bcm5719-llvm-194b337f3327691ee88007061c71225c934b3af0.zip |
Avoid eager template instantiation caused by the variant narrowing checks.
The standard disallows narrowing conversions when constructing a variant.
This is checked by attempting to perform braced initialization of the
destination type from the argument type. However, braced initialization
can force the compiler (mostly clang) to eagerly instantiate the
constructors of the destintation type -- which can lead to errors in
a non-immediate context.
However, as variant is currently specified, the narrowing checks only
observably apply when the destination type is arithmetic. Meaning we can
skip the check for class types. Hense avoiding the hard errors.
In order to cause fewer build breakages, this patch avoids the narrowing
check except when the destination type is arithmetic.
llvm-svn: 366022
Diffstat (limited to 'libcxx/test/std/utilities')
-rw-r--r-- | libcxx/test/std/utilities/variant/variant.variant/variant.ctor/T.pass.cpp | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/libcxx/test/std/utilities/variant/variant.variant/variant.ctor/T.pass.cpp b/libcxx/test/std/utilities/variant/variant.variant/variant.ctor/T.pass.cpp index 55f8d11c115..ef074828581 100644 --- a/libcxx/test/std/utilities/variant/variant.variant/variant.ctor/T.pass.cpp +++ b/libcxx/test/std/utilities/variant/variant.variant/variant.ctor/T.pass.cpp @@ -177,10 +177,22 @@ void test_T_ctor_basic() { #endif } +struct BoomOnInt { + template <class T> + constexpr BoomOnInt(T) { static_assert(!std::is_same<T, int>::value, ""); } +}; + +void test_no_narrowing_check_for_class_types() { + using V = std::variant<int, BoomOnInt>; + V v(42); + assert(v.index() == 0); + assert(std::get<0>(v) == 42); +} + int main(int, char**) { test_T_ctor_basic(); test_T_ctor_noexcept(); test_T_ctor_sfinae(); - + test_no_narrowing_check_for_class_types(); return 0; } |