[libcxx-commits] [PATCH] D74184: Test std::equal with type qualified pointers

Tom Rix via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Thu Feb 6 17:09:18 PST 2020


trixirt created this revision.
trixirt added reviewers: mclow.lists, howard.hinnant.
trixirt added a project: libc++.
Herald added subscribers: libcxx-commits, christof.

Problem using std::mismatch with volatile * reduces to same problem with std::equal.

Template expansion does not match from include/algorithms because its  addition of 'const' conflicts with 'volatile'

In file included from .../libcxx/test/std/algorithms/alg.nonmodifying/alg.equal/equal_type_qualifie\
r.pass.cpp:9:                                                                                                                                    
.../libcxx/include/algorithm: In instantiation of ‘constexpr bool std::__1::equal(_InputIterator1, \
_InputIterator1, _InputIterator2, _BinaryPredicate) [with _InputIterator1 = volatile char*; _InputIterator2 = volatile char*; _BinaryPredicate =\
 std::__1::__equal_to<char, char>]’:                                                                                                             
.../libcxx/include/algorithm:1275:24:   required from ‘constexpr bool std::__1::equal(_InputIterato\
r1, _InputIterator1, _InputIterator2) [with _InputIterator1 = volatile char*; _InputIterator2 = volatile char*]’                                 
.../libcxx/test/std/algorithms/alg.nonmodifying/alg.equal/equal_type_qualifier.pass.cpp:17:3:   req\
uired from here                                                                                                                                  
.../libcxx/include/algorithm:1262:20: error: no match for call to ‘(std::__1::__equal_to<char, char\

> ) (volatile char&, volatile char&)’

1262 |         if (!__pred(*__first1, *__first2))

  |              ~~~~~~^~~~~~~~~~~~~~~~~~~~~~                                                                                                

.../libcxx/include/algorithm:678:10: note: candidate: ‘constexpr bool std::__1::__equal_to<_T1, _T1\

> ::operator()(const _T1&, const _T1&) const [with _T1 = char]’ (near match)

  678 |     bool operator()(const _T1& __x, const _T1& __y) const {return __x == __y;}                                                           
      |          ^~~~~~~~                                                                                                                        

.../libcxx/include/algorithm:678:10: note:   conversion of argument 2 would be ill-formed:          
.../libcxx/include/algorithm:1262:20: error: binding reference of type ‘const char&’ to ‘volatile c\
har’ discards qualifiers                                                                                                                         
 1262 |         if (!__pred(*__first1, *__first2))


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D74184

Files:
  libcxx/test/std/algorithms/alg.nonmodifying/alg.equal/equal_type_qualifier.pass.cpp


Index: libcxx/test/std/algorithms/alg.nonmodifying/alg.equal/equal_type_qualifier.pass.cpp
===================================================================
--- /dev/null
+++ libcxx/test/std/algorithms/alg.nonmodifying/alg.equal/equal_type_qualifier.pass.cpp
@@ -0,0 +1,20 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include <algorithm>
+#include <cassert>
+int main(int, char**) {
+  char* a;
+  assert(std::equal(a, a, a));
+  const char* b;
+  assert(std::equal(b, b, b));
+  volatile char* c;
+  assert(std::equal(c, c, c));
+
+  return 0;
+}


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D74184.243054.patch
Type: text/x-patch
Size: 888 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20200207/1777b666/attachment.bin>


More information about the libcxx-commits mailing list