[llvm] r369500 - [NFC] Mark CallTargetComparator() as const to fix libc++ warnings

Raphael Isemann via llvm-commits llvm-commits at lists.llvm.org
Wed Aug 21 00:39:17 PDT 2019


Author: teemperor
Date: Wed Aug 21 00:39:17 2019
New Revision: 369500

URL: http://llvm.org/viewvc/llvm-project?rev=369500&view=rev
Log:
[NFC] Mark CallTargetComparator() as const to fix libc++ warnings

We currently get this warning when compiling with libc++:

/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/set:454:26: warning: the specified comparator type does not provide a const call operator [-Wuser-defined-warnings]
    static_assert(sizeof(__diagnose_non_const_comparator<_Key, _Compare>()), "");
                         ^
llvm-project/llvm/include/llvm/ProfileData/SampleProf.h:193:29: note: in instantiation of template class 'std::__1::set<std::__1::pair<llvm::StringRef, unsigned long long>, llvm::sampleprof::SampleRecord::CallTargetComparator, std::__1::allocator<std::__1::pair<llvm::StringRef, unsigned long long> > >' requested here
  const SortedCallTargetSet getSortedCallTargets() const {
                            ^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/__tree:967:5: note: from 'diagnose_if' attribute on '__diagnose_non_const_comparator<std::__1::pair<llvm::StringRef, unsigned long long>, llvm::sampleprof::SampleRecord::CallTargetComparator>':
    _LIBCPP_DIAGNOSE_WARNING(!std::__invokable<_Compare const&, _Tp const&, _Tp const&>::value,
    ^                        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/__config:1320:21: note: expanded from macro '_LIBCPP_DIAGNOSE_WARNING'
     __attribute__((diagnose_if(__VA_ARGS__, "warning")))
                    ^           ~~~~~~~~~~~
1 warning generated.

Modified:
    llvm/trunk/include/llvm/ProfileData/SampleProf.h

Modified: llvm/trunk/include/llvm/ProfileData/SampleProf.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ProfileData/SampleProf.h?rev=369500&r1=369499&r2=369500&view=diff
==============================================================================
--- llvm/trunk/include/llvm/ProfileData/SampleProf.h (original)
+++ llvm/trunk/include/llvm/ProfileData/SampleProf.h Wed Aug 21 00:39:17 2019
@@ -146,7 +146,7 @@ class SampleRecord {
 public:
   using CallTarget = std::pair<StringRef, uint64_t>;
   struct CallTargetComparator {
-    bool operator() (const CallTarget &LHS, const CallTarget &RHS) {
+    bool operator()(const CallTarget &LHS, const CallTarget &RHS) const {
       if (LHS.second != RHS.second)
         return LHS.second > RHS.second;
 




More information about the llvm-commits mailing list