public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* Add workaround to std::variant for Clang bug 31852
@ 2018-03-26 13:13 Jonathan Wakely
  2018-03-26 14:14 ` Jonathan Wakely
  2018-04-05 16:59 ` Jonathan Wakely
  0 siblings, 2 replies; 4+ messages in thread
From: Jonathan Wakely @ 2018-03-26 13:13 UTC (permalink / raw)
  To: libstdc++, gcc-patches

This makes it possible to use our std::variant with Clang, as well as
some minor tweaks to avoid ADL (so the compiler doesn't waste time
looking in associated namespaces) and adjust whitespace.

       * include/std/variant (__get): Qualify calls to avoid ADL.
       (__select_index): Adjust whitespace.
       (variant): Add using-declaration to workaround Clang bug.

Tested powerpc64le-linux, committed to trunk.. I'll backport to
gcc-7-branch too.

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

* Re: Add workaround to std::variant for Clang bug 31852
  2018-03-26 13:13 Add workaround to std::variant for Clang bug 31852 Jonathan Wakely
@ 2018-03-26 14:14 ` Jonathan Wakely
  2018-04-07 15:13   ` Gerald Pfeifer
  2018-04-05 16:59 ` Jonathan Wakely
  1 sibling, 1 reply; 4+ messages in thread
From: Jonathan Wakely @ 2018-03-26 14:14 UTC (permalink / raw)
  To: libstdc++, gcc-patches

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

Now with 100% more patch.



On 26 March 2018 at 14:10, Jonathan Wakely <jwakely.gcc@gmail.com> wrote:
> This makes it possible to use our std::variant with Clang, as well as
> some minor tweaks to avoid ADL (so the compiler doesn't waste time
> looking in associated namespaces) and adjust whitespace.
>
>        * include/std/variant (__get): Qualify calls to avoid ADL.
>        (__select_index): Adjust whitespace.
>        (variant): Add using-declaration to workaround Clang bug.
>
> Tested powerpc64le-linux, committed to trunk.. I'll backport to
> gcc-7-branch too.

[-- Attachment #2: patch.txt --]
[-- Type: text/plain, Size: 2126 bytes --]

commit 4b3007fd674c489b695b8b1c52d6f1e8d010f072
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Mon Mar 26 13:49:34 2018 +0100

    Add workaround to std::variant for Clang bug 31852
    
            * include/std/variant (__get): Qualify calls to avoid ADL.
            (__select_index): Adjust whitespace.
            (variant): Add using-declaration to workaround Clang bug.

diff --git a/libstdc++-v3/include/std/variant b/libstdc++-v3/include/std/variant
index 4aba131cb73..e4ae6573ed4 100644
--- a/libstdc++-v3/include/std/variant
+++ b/libstdc++-v3/include/std/variant
@@ -223,13 +223,17 @@ namespace __variant
 
   template<size_t _Np, typename _Union>
     constexpr decltype(auto) __get(in_place_index_t<_Np>, _Union&& __u)
-    { return __get(in_place_index<_Np-1>, std::forward<_Union>(__u)._M_rest); }
+    {
+      return __variant::__get(in_place_index<_Np-1>,
+			      std::forward<_Union>(__u)._M_rest);
+    }
 
   // Returns the typed storage for __v.
   template<size_t _Np, typename _Variant>
     constexpr decltype(auto) __get(_Variant&& __v)
     {
-      return __get(std::in_place_index<_Np>, std::forward<_Variant>(__v)._M_u);
+      return __variant::__get(std::in_place_index<_Np>,
+			      std::forward<_Variant>(__v)._M_u);
     }
 
   // Various functions as "vtable" entries, where those vtables are used by
@@ -358,10 +362,9 @@ namespace __variant
 
   template <typename... _Types>
   using __select_index =
-    typename __select_int::_Select_int_base<sizeof...(_Types)+1,
+    typename __select_int::_Select_int_base<sizeof...(_Types) + 1,
 					    unsigned char,
-					    unsigned short>
-    ::type::value_type;
+					    unsigned short>::type::value_type;
 
   template<typename... _Types>
     struct _Variant_storage<false, _Types...>
@@ -1304,6 +1307,12 @@ namespace __variant
 
 #undef _VARIANT_RELATION_FUNCTION_TEMPLATE
 
+#ifdef __clang__
+    public:
+      using _Base::_M_u; // See https://bugs.llvm.org/show_bug.cgi?id=31852
+    private:
+#endif
+
       template<size_t _Np, typename _Vp>
 	friend constexpr decltype(auto) __detail::__variant::__get(_Vp&& __v);
 

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

* Re: Add workaround to std::variant for Clang bug 31852
  2018-03-26 13:13 Add workaround to std::variant for Clang bug 31852 Jonathan Wakely
  2018-03-26 14:14 ` Jonathan Wakely
@ 2018-04-05 16:59 ` Jonathan Wakely
  1 sibling, 0 replies; 4+ messages in thread
From: Jonathan Wakely @ 2018-04-05 16:59 UTC (permalink / raw)
  To: libstdc++, gcc-patches

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

On 26 March 2018 at 14:10, Jonathan Wakely wrote:
> This makes it possible to use our std::variant with Clang, as well as
> some minor tweaks to avoid ADL (so the compiler doesn't waste time
> looking in associated namespaces) and adjust whitespace.
>
>        * include/std/variant (__get): Qualify calls to avoid ADL.
>        (__select_index): Adjust whitespace.
>        (variant): Add using-declaration to workaround Clang bug.
>
> Tested powerpc64le-linux, committed to trunk.. I'll backport to
> gcc-7-branch too.

The Clang bug means that __get is ambiguous (because it thinks the
friend declaration is a separate overload) so we also need this
change.

Tested powerpc64le-linux, committed to trunk.

[-- Attachment #2: patch.txt --]
[-- Type: text/plain, Size: 999 bytes --]

commit c09f881053d98370306098b7bad5bb829255379c
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Thu Apr 5 14:03:13 2018 +0100

    Add another workaround to std::variant for Clang bug 31852
    
            * include/std/variant (_VARIANT_RELATION_FUNCTION_TEMPLATE): Qualify
            __get calls to avoid ADL and avoid ambiguity due to Clang bug.

diff --git a/libstdc++-v3/include/std/variant b/libstdc++-v3/include/std/variant
index 028d3064272..48bec528406 100644
--- a/libstdc++-v3/include/std/variant
+++ b/libstdc++-v3/include/std/variant
@@ -272,8 +272,8 @@ namespace __variant
     constexpr bool \
     __erased_##__NAME(const _Variant& __lhs, const _Variant& __rhs) \
     { \
-      return __get<_Np>(std::forward<_Variant>(__lhs)) \
-	  __OP __get<_Np>(std::forward<_Variant>(__rhs)); \
+      return __variant::__get<_Np>(std::forward<_Variant>(__lhs)) \
+	  __OP __variant::__get<_Np>(std::forward<_Variant>(__rhs)); \
     }
 
   _VARIANT_RELATION_FUNCTION_TEMPLATE(<, less)

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

* Re: Add workaround to std::variant for Clang bug 31852
  2018-03-26 14:14 ` Jonathan Wakely
@ 2018-04-07 15:13   ` Gerald Pfeifer
  0 siblings, 0 replies; 4+ messages in thread
From: Gerald Pfeifer @ 2018-04-07 15:13 UTC (permalink / raw)
  To: Jonathan Wakely; +Cc: libstdc++, gcc-patches

On Mon, 26 Mar 2018, Jonathan Wakely wrote:
> Now with 100% more patch.

Technically infinitely more patch, not just 100%. :-)

(The previous mail had 100% less patch, though.)

SCNR,
Gerald

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

end of thread, other threads:[~2018-04-07 15:13 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-03-26 13:13 Add workaround to std::variant for Clang bug 31852 Jonathan Wakely
2018-03-26 14:14 ` Jonathan Wakely
2018-04-07 15:13   ` Gerald Pfeifer
2018-04-05 16:59 ` 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).