Fix for PRPR17934; based on a fix suggested by Peter Sommerlad

git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@196058 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/include/iterator b/include/iterator
index d16aa2a..1c59919 100644
--- a/include/iterator
+++ b/include/iterator
@@ -1387,6 +1387,22 @@
 
 #if !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_TRAILING_RETURN)
 
+template <class _Tp, size_t _Np>
+inline _LIBCPP_INLINE_VISIBILITY
+_Tp*
+begin(_Tp (&__array)[_Np])
+{
+    return __array;
+}
+
+template <class _Tp, size_t _Np>
+inline _LIBCPP_INLINE_VISIBILITY
+_Tp*
+end(_Tp (&__array)[_Np])
+{
+    return __array + _Np;
+}
+
 template <class _Cp>
 inline _LIBCPP_INLINE_VISIBILITY
 auto
@@ -1421,18 +1437,46 @@
 
 #if _LIBCPP_STD_VER > 11
 
+template <class _Tp, size_t _Np>
+inline _LIBCPP_INLINE_VISIBILITY
+reverse_iterator<_Tp*> rbegin(_Tp (&__array)[_Np])
+{
+    return reverse_iterator<_Tp*>(__array + _Np);
+}
+
+template <class _Tp, size_t _Np>
+inline _LIBCPP_INLINE_VISIBILITY
+reverse_iterator<_Tp*> rend(_Tp (&__array)[_Np])
+{
+    return reverse_iterator<_Tp*>(__array);
+}
+
+template <class _Ep>
+inline _LIBCPP_INLINE_VISIBILITY
+reverse_iterator<const _Ep*> rbegin(initializer_list<_Ep> __il)
+{
+    return reverse_iterator<const _Ep*>(__il.end());
+}
+
+template <class _Ep>
+inline _LIBCPP_INLINE_VISIBILITY
+reverse_iterator<const _Ep*> rend(initializer_list<_Ep> __il)
+{
+    return reverse_iterator<const _Ep*>(__il.begin());
+}
+
 template <class _Cp>
 inline _LIBCPP_INLINE_VISIBILITY
 auto cbegin(const _Cp& __c) -> decltype(begin(__c))
 {
-    return __c.begin();
+    return _VSTD::begin(__c);
 }
 
 template <class _Cp>
 inline _LIBCPP_INLINE_VISIBILITY
 auto cend(const _Cp& __c) -> decltype(end(__c))
 {
-    return __c.end();
+    return _VSTD::end(__c);
 }
 
 template <class _Cp>
@@ -1516,53 +1560,6 @@
 
 #endif  // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_TRAILING_RETURN)
 
-template <class _Tp, size_t _Np>
-inline _LIBCPP_INLINE_VISIBILITY
-_Tp*
-begin(_Tp (&__array)[_Np])
-{
-    return __array;
-}
-
-template <class _Tp, size_t _Np>
-inline _LIBCPP_INLINE_VISIBILITY
-_Tp*
-end(_Tp (&__array)[_Np])
-{
-    return __array + _Np;
-}
-
-#if _LIBCPP_STD_VER > 11
-template <class _Tp, size_t _Np>
-inline _LIBCPP_INLINE_VISIBILITY
-reverse_iterator<_Tp*> rbegin(_Tp (&__array)[_Np])
-{
-    return reverse_iterator<_Tp*>(__array + _Np);
-}
-
-template <class _Tp, size_t _Np>
-inline _LIBCPP_INLINE_VISIBILITY
-reverse_iterator<_Tp*> rend(_Tp (&__array)[_Np])
-{
-    return reverse_iterator<_Tp*>(__array);
-}
-
-template <class _Ep>
-inline _LIBCPP_INLINE_VISIBILITY
-reverse_iterator<const _Ep*> rbegin(initializer_list<_Ep> __il)
-{
-    return reverse_iterator<const _Ep*>(__il.end());
-}
-
-template <class _Ep>
-inline _LIBCPP_INLINE_VISIBILITY
-reverse_iterator<const _Ep*> rend(initializer_list<_Ep> __il)
-{
-    return reverse_iterator<const _Ep*>(__il.begin());
-}
-
-#endif
-
 _LIBCPP_END_NAMESPACE_STD
 
 #endif  // _LIBCPP_ITERATOR