]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
libstdc++: Add test for std::con/disjunction's short circuiting
authorPatrick Palka <ppalka@redhat.com>
Wed, 31 Aug 2022 14:04:54 +0000 (10:04 -0400)
committerPatrick Palka <ppalka@redhat.com>
Wed, 31 Aug 2022 14:04:54 +0000 (10:04 -0400)
libstdc++-v3/ChangeLog:

* testsuite/20_util/logical_traits/requirements/short_circuit.cc: New test.

libstdc++-v3/testsuite/20_util/logical_traits/requirements/short_circuit.cc [new file with mode: 0644]

diff --git a/libstdc++-v3/testsuite/20_util/logical_traits/requirements/short_circuit.cc b/libstdc++-v3/testsuite/20_util/logical_traits/requirements/short_circuit.cc
new file mode 100644 (file)
index 0000000..86996b2
--- /dev/null
@@ -0,0 +1,26 @@
+// { dg-do compile { target c++17 } }
+
+#include <type_traits>
+
+template<class T> struct A { using type = typename T::type; };
+using invalid = A<void>;
+
+// [meta.logical]/3: For a specialization conjunction<B_1, ..., B_n>, if
+// there is a template type argument B_i for which bool(B_i::value) is false,
+// then instantiating conjunction<B_1, ..., B_n>::value does not require the
+// instantiation of B_j::value for j > i.
+
+static_assert(!std::conjunction_v<std::false_type, invalid>);
+static_assert(!std::conjunction_v<std::false_type, invalid, invalid>);
+static_assert(!std::conjunction_v<std::true_type, std::false_type, invalid>);
+static_assert(!std::conjunction_v<std::true_type, std::false_type, invalid, invalid>);
+
+// [meta.logical]/8: For a specialization disjunction<B_1, ..., B_n>, if
+// there is a template type argument B_i for which bool(B_i::value) is true,
+// then instantiating disjunction<B_1, ..., B_n>::value does not require the
+// instantiation of B_j::value for j > i.
+
+static_assert(std::disjunction_v<std::true_type, invalid>);
+static_assert(std::disjunction_v<std::true_type, invalid, invalid>);
+static_assert(std::disjunction_v<std::false_type, std::true_type, invalid>);
+static_assert(std::disjunction_v<std::false_type, std::true_type, invalid, invalid>);