public inbox for libstdc++@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] libstdc++: Add test for std::con/disjunction's short circuiting
@ 2022-08-30 17:14 Patrick Palka
  2022-08-31  9:41 ` Jonathan Wakely
  0 siblings, 1 reply; 2+ messages in thread
From: Patrick Palka @ 2022-08-30 17:14 UTC (permalink / raw)
  To: gcc-patches; +Cc: libstdc++, Patrick Palka

Tested on x86_64-pc-linux-gnu, does this look OK for trunk?

libstdc++-v3/ChangeLog:

	* testsuite/20_util/logical_traits/requirements/short_circuit.cc: New test.
---
 .../requirements/short_circuit.cc             | 32 +++++++++++++++++++
 1 file changed, 32 insertions(+)
 create mode 100644 libstdc++-v3/testsuite/20_util/logical_traits/requirements/short_circuit.cc

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
index 00000000000..b6a8091cdb0
--- /dev/null
+++ b/libstdc++-v3/testsuite/20_util/logical_traits/requirements/short_circuit.cc
@@ -0,0 +1,32 @@
+// { 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::false_type>);
+
+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>);
+static_assert(!std::conjunction_v<std::true_type, std::false_type>);
+
+// [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::true_type>);
+
+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>);
+static_assert(std::disjunction_v<std::false_type, std::true_type>);
-- 
2.37.2.490.g6c8e4ee870


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] libstdc++: Add test for std::con/disjunction's short circuiting
  2022-08-30 17:14 [PATCH] libstdc++: Add test for std::con/disjunction's short circuiting Patrick Palka
@ 2022-08-31  9:41 ` Jonathan Wakely
  0 siblings, 0 replies; 2+ messages in thread
From: Jonathan Wakely @ 2022-08-31  9:41 UTC (permalink / raw)
  To: Patrick Palka; +Cc: gcc-patches, libstdc++

On Tue, 30 Aug 2022 at 18:14, Patrick Palka via Libstdc++
<libstdc++@gcc.gnu.org> wrote:
>
> Tested on x86_64-pc-linux-gnu, does this look OK for trunk?

Yes, thanks for adding this.

>
> libstdc++-v3/ChangeLog:
>
>         * testsuite/20_util/logical_traits/requirements/short_circuit.cc: New test.
> ---
>  .../requirements/short_circuit.cc             | 32 +++++++++++++++++++
>  1 file changed, 32 insertions(+)
>  create mode 100644 libstdc++-v3/testsuite/20_util/logical_traits/requirements/short_circuit.cc
>
> 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
> index 00000000000..b6a8091cdb0
> --- /dev/null
> +++ b/libstdc++-v3/testsuite/20_util/logical_traits/requirements/short_circuit.cc
> @@ -0,0 +1,32 @@
> +// { 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::false_type>);
> +
> +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>);
> +static_assert(!std::conjunction_v<std::true_type, std::false_type>);
> +
> +// [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::true_type>);
> +
> +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>);
> +static_assert(std::disjunction_v<std::false_type, std::true_type>);
> --
> 2.37.2.490.g6c8e4ee870
>


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-08-31  9:41 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-08-30 17:14 [PATCH] libstdc++: Add test for std::con/disjunction's short circuiting Patrick Palka
2022-08-31  9:41 ` Jonathan Wakely

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).