public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* libstdc++: Fix visitor return type diagnostics [PR97499]
@ 2020-10-16  7:26 Ville Voutilainen
  2020-10-16 10:02 ` Jonathan Wakely
  0 siblings, 1 reply; 3+ messages in thread
From: Ville Voutilainen @ 2020-10-16  7:26 UTC (permalink / raw)
  To: gcc-patches List, libstdc++

[-- Attachment #1: Type: text/plain, Size: 625 bytes --]

Tested on Linux-PPC64. I haven't tested this with clang yet,
Jonathan, can you help with that? The previous implementation
indeed made an if-constexpr branch invalid for all instantiations
of that branch, this one doesn't - now we have just a dependent static_assert
which is well-formed for correct visitors and ill-formed for incorrect
visitors.

2020-10-16  Ville Voutilainen  <ville.voutilainen@gmail.com>

    PR libstdc++/97449
    * include/std/variant
    (__gen_vtable_impl<>::_S_apply_single_alt):
    Diagnose visitor return type mismatches here..
    (__gen_vtable_impl</*base case*/>::_S_apply):
    ..not here.

[-- Attachment #2: pr97449.diff --]
[-- Type: text/x-patch, Size: 1136 bytes --]

diff --git a/libstdc++-v3/include/std/variant b/libstdc++-v3/include/std/variant
index a29c5bf513b..17f8bcd638b 100644
--- a/libstdc++-v3/include/std/variant
+++ b/libstdc++-v3/include/std/variant
@@ -960,9 +960,13 @@ namespace __variant
 	    }
 	  else
 	    {
-	      __element = __gen_vtable_impl<
+	      auto __tmp_element = __gen_vtable_impl<
 		remove_reference_t<decltype(__element)>,
 		std::index_sequence<__indices..., __index>>::_S_apply();
+	      static_assert(is_same_v<_Tp, decltype(__tmp_element)>,
+			    "std::visit requires the visitor to have the same "
+			    "return type for all alternatives of a variant");
+	      __element = __tmp_element;
 	    }
 	}
     };
@@ -1026,10 +1030,8 @@ namespace __variant
 				    std::declval<_Variants>()...))>;
 	    if constexpr (__visit_ret_type_mismatch)
 	      {
-		static_assert(!__visit_ret_type_mismatch,
-		  "std::visit requires the visitor to have the same "
-		  "return type for all alternatives of a variant");
-		return __nonesuch{};
+		struct __cannot_match {};
+		return __cannot_match{};
 	      }
 	    else
 	      return _Array_type{&__visit_invoke};

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

* Re: libstdc++: Fix visitor return type diagnostics [PR97499]
  2020-10-16  7:26 libstdc++: Fix visitor return type diagnostics [PR97499] Ville Voutilainen
@ 2020-10-16 10:02 ` Jonathan Wakely
  2020-10-17 20:08   ` Ville Voutilainen
  0 siblings, 1 reply; 3+ messages in thread
From: Jonathan Wakely @ 2020-10-16 10:02 UTC (permalink / raw)
  To: Ville Voutilainen; +Cc: gcc-patches List, libstdc++

On 16/10/20 10:26 +0300, Ville Voutilainen via Libstdc++ wrote:
>Tested on Linux-PPC64. I haven't tested this with clang yet,
>Jonathan, can you help with that? The previous implementation
>indeed made an if-constexpr branch invalid for all instantiations
>of that branch, this one doesn't - now we have just a dependent static_assert
>which is well-formed for correct visitors and ill-formed for incorrect
>visitors.

All I checked is that <variant> can now be included using -std=c++17,
but that works with Clang.

OK for trunk, thanks.


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

* Re: libstdc++: Fix visitor return type diagnostics [PR97499]
  2020-10-16 10:02 ` Jonathan Wakely
@ 2020-10-17 20:08   ` Ville Voutilainen
  0 siblings, 0 replies; 3+ messages in thread
From: Ville Voutilainen @ 2020-10-17 20:08 UTC (permalink / raw)
  To: Jonathan Wakely; +Cc: gcc-patches List, libstdc++

On Fri, 16 Oct 2020 at 13:02, Jonathan Wakely <jwakely@redhat.com> wrote:
>
> On 16/10/20 10:26 +0300, Ville Voutilainen via Libstdc++ wrote:
> >Tested on Linux-PPC64. I haven't tested this with clang yet,
> >Jonathan, can you help with that? The previous implementation
> >indeed made an if-constexpr branch invalid for all instantiations
> >of that branch, this one doesn't - now we have just a dependent static_assert
> >which is well-formed for correct visitors and ill-formed for incorrect
> >visitors.
>
> All I checked is that <variant> can now be included using -std=c++17,
> but that works with Clang.
>
> OK for trunk, thanks.

The subject line is wrong, this is 97449, not 97499. Fixing that and pushing.

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

end of thread, other threads:[~2020-10-17 20:08 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-16  7:26 libstdc++: Fix visitor return type diagnostics [PR97499] Ville Voutilainen
2020-10-16 10:02 ` Jonathan Wakely
2020-10-17 20:08   ` Ville Voutilainen

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).