[clang-tools-extra] r329452 - [clang-tidy] Fix compilation for ParentVirtualCallCheck.cpp

Alexander Kornienko via cfe-commits cfe-commits at lists.llvm.org
Tue Apr 10 08:28:43 PDT 2018


On Mon, Apr 9, 2018 at 8:09 PM Zinovy Nis <zinovy.nis at gmail.com> wrote:

> I had compilation errors here on MVSV at PSP and for ARM:
>
> ------------------------
>
> FAILED: /usr/bin/c++   -DGTEST_HAS_RTTI=0 -D_DEBUG -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -Itools/clang/tools/extra/clang-tidy/bugprone -I/home/uweigand/sandbox/buildbot/clang-s390x-linux-multistage/llvm/tools/clang/tools/extra/clang-tidy/bugprone -I/home/uweigand/sandbox/buildbot/clang-s390x-linux-multistage/llvm/tools/clang/include -Itools/clang/include -Iinclude -I/home/uweigand/sandbox/buildbot/clang-s390x-linux-multistage/llvm/include -fPIC -fvisibility-inlines-hidden -Werror=date-time -std=c++11 -Wall -W -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wno-missing-field-initializers -pedantic -Wno-long-long -Wno-maybe-uninitialized -Wdelete-non-virtual-dtor -Wno-comment -ffunction-sections -fdata-sections -fno-common -Woverloaded-virtual -fno-strict-aliasing -O3    -UNDEBUG  -fno-exceptions -fno-rtti -MMD -MT tools/clang/tools/extra/clang-tidy/bugprone/CMakeFiles/clangTidyBugproneModule.dir/ParentVirtualCallCheck.cpp.o -MF tools/clang/tools/extra/clang-tidy/bugprone/CMakeFiles/clangTidyBugproneModule.dir/ParentVirtualCallCheck.cpp.o.d -o tools/clang/tools/extra/clang-tidy/bugprone/CMakeFiles/clangTidyBugproneModule.dir/ParentVirtualCallCheck.cpp.o -c /home/uweigand/sandbox/buildbot/clang-s390x-linux-multistage/llvm/tools/clang/tools/extra/clang-tidy/bugprone/ParentVirtualCallCheck.cpp
> /home/uweigand/sandbox/buildbot/clang-s390x-linux-multistage/llvm/tools/clang/tools/extra/clang-tidy/bugprone/ParentVirtualCallCheck.cpp: In function 'bool clang::tidy::bugprone::isParentOf(const clang::CXXRecordDecl&, const clang::CXXRecordDecl&)':
> /home/uweigand/sandbox/buildbot/clang-s390x-linux-multistage/llvm/tools/clang/tools/extra/clang-tidy/bugprone/ParentVirtualCallCheck.cpp:30:63: error: use of 'auto' in lambda parameter declaration only available with -std=c++14 or -std=gnu++14
>    const auto ClassIter = llvm::find_if(ThisClass.bases(), [=](auto &Base) {
>                                                                ^
>
> But that seems to be unrelated to llvm::find_if? The compiler is
complaining about the use of `auto` in the lambda argument type.


>
> /home/uweigand/sandbox/buildbot/clang-s390x-linux-multistage/llvm/tools/clang/tools/extra/clang-tidy/bugprone/ParentVirtualCallCheck.cpp: In lambda function:
> /home/uweigand/sandbox/buildbot/clang-s390x-linux-multistage/llvm/tools/clang/tools/extra/clang-tidy/bugprone/ParentVirtualCallCheck.cpp:31:27: error: request for member 'getType' in 'Base', which is of non-class type 'int'
>      auto *BaseDecl = Base.getType()->getAsCXXRecordDecl();
>                            ^
> /home/uweigand/sandbox/buildbot/clang-s390x-linux-multistage/llvm/tools/clang/tools/extra/clang-tidy/bugprone/ParentVirtualCallCheck.cpp: In function 'std::__cxx11::string clang::tidy::bugprone::getExprAsString(const clang::Expr&, clang::ASTContext&)':
> /home/uweigand/sandbox/buildbot/clang-s390x-linux-multistage/llvm/tools/clang/tools/extra/clang-tidy/bugprone/ParentVirtualCallCheck.cpp:77:48: error: no matching function for call to 'remove_if(std::__cxx11::string&, <unresolved overloaded function type>)'
>    Text.erase(llvm::remove_if(Text, std::isspace), Text.end());
>                                                 ^
>
> It also doesn't look specific to llvm::remove_if. That can be fixed either
by wrapping std::isspace into a lambda or by using a static_cast<int
(*)(int)> to select the right overload.


>
> In file included from /home/uweigand/sandbox/buildbot/clang-s390x-linux-multistage/llvm/include/llvm/ADT/StringRef.h:13:0,
>                  from /home/uweigand/sandbox/buildbot/clang-s390x-linux-multistage/llvm/include/llvm/ADT/StringMap.h:17,
>                  from /home/uweigand/sandbox/buildbot/clang-s390x-linux-multistage/llvm/tools/clang/tools/extra/clang-tidy/bugprone/../ClangTidyOptions.h:14,
>                  from /home/uweigand/sandbox/buildbot/clang-s390x-linux-multistage/llvm/tools/clang/tools/extra/clang-tidy/bugprone/../ClangTidyDiagnosticConsumer.h:13,
>                  from /home/uweigand/sandbox/buildbot/clang-s390x-linux-multistage/llvm/tools/clang/tools/extra/clang-tidy/bugprone/../ClangTidy.h:13,
>                  from /home/uweigand/sandbox/buildbot/clang-s390x-linux-multistage/llvm/tools/clang/tools/extra/clang-tidy/bugprone/ParentVirtualCallCheck.h:13,
>                  from /home/uweigand/sandbox/buildbot/clang-s390x-linux-multistage/llvm/tools/clang/tools/extra/clang-tidy/bugprone/ParentVirtualCallCheck.cpp:10:
> /home/uweigand/sandbox/buildbot/clang-s390x-linux-multistage/llvm/include/llvm/ADT/STLExtras.h:886:6: note: candidate: template<class R, class UnaryPredicate> decltype (llvm::adl_begin(Range)) llvm::remove_if(R&&, UnaryPredicate)
>  auto remove_if(R &&Range, UnaryPredicate P) -> decltype(adl_begin(Range)) {
>       ^
> /home/uweigand/sandbox/buildbot/clang-s390x-linux-multistage/llvm/include/llvm/ADT/STLExtras.h:886:6: note:   template argument deduction/substitution failed:
> /home/uweigand/sandbox/buildbot/clang-s390x-linux-multistage/llvm/tools/clang/tools/extra/clang-tidy/bugprone/ParentVirtualCallCheck.cpp:77:48: note:   couldn't deduce template parameter 'UnaryPredicate'
>    Text.erase(llvm::remove_if(Text, std::isspace), Text.end());
>                                                 ^
> In file included from /usr/include/c++/5/bits/stl_algobase.h:71:0,
>                  from /usr/include/c++/5/algorithm:61,
>                  from /home/uweigand/sandbox/buildbot/clang-s390x-linux-multistage/llvm/include/llvm/ADT/Optional.h:23,
>                  from /home/uweigand/sandbox/buildbot/clang-s390x-linux-multistage/llvm/tools/clang/tools/extra/clang-tidy/bugprone/../ClangTidyOptions.h:13,
>                  from /home/uweigand/sandbox/buildbot/clang-s390x-linux-multistage/llvm/tools/clang/tools/extra/clang-tidy/bugprone/../ClangTidyDiagnosticConsumer.h:13,
>                  from /home/uweigand/sandbox/buildbot/clang-s390x-linux-multistage/llvm/tools/clang/tools/extra/clang-tidy/bugprone/../ClangTidy.h:13,
>                  from /home/uweigand/sandbox/buildbot/clang-s390x-linux-multistage/llvm/tools/clang/tools/extra/clang-tidy/bugprone/ParentVirtualCallCheck.h:13,
>                  from /home/uweigand/sandbox/buildbot/clang-s390x-linux-multistage/llvm/tools/clang/tools/extra/clang-tidy/bugprone/ParentVirtualCallCheck.cpp:10:
> /usr/include/c++/5/bits/predefined_ops.h: In instantiation of 'bool __gnu_cxx::__ops::_Iter_pred<_Predicate>::operator()(_Iterator) [with _Iterator = const clang::CXXBaseSpecifier*; _Predicate = clang::tidy::bugprone::isParentOf(const clang::CXXRecordDecl&, const clang::CXXRecordDecl&)::<lambda(int&)>]':
> /usr/include/c++/5/bits/stl_algo.h:120:14:   required from '_RandomAccessIterator std::__find_if(_RandomAccessIterator, _RandomAccessIterator, _Predicate, std::random_access_iterator_tag) [with _RandomAccessIterator = const clang::CXXBaseSpecifier*; _Predicate = __gnu_cxx::__ops::_Iter_pred<clang::tidy::bugprone::isParentOf(const clang::CXXRecordDecl&, const clang::CXXRecordDecl&)::<lambda(int&)> >]'
> /usr/include/c++/5/bits/stl_algo.h:161:23:   required from '_Iterator std::__find_if(_Iterator, _Iterator, _Predicate) [with _Iterator = const clang::CXXBaseSpecifier*; _Predicate = __gnu_cxx::__ops::_Iter_pred<clang::tidy::bugprone::isParentOf(const clang::CXXRecordDecl&, const clang::CXXRecordDecl&)::<lambda(int&)> >]'
> /usr/include/c++/5/bits/stl_algo.h:3815:28:   required from '_IIter std::find_if(_IIter, _IIter, _Predicate) [with _IIter = const clang::CXXBaseSpecifier*; _Predicate = clang::tidy::bugprone::isParentOf(const clang::CXXRecordDecl&, const clang::CXXRecordDecl&)::<lambda(int&)>]'
> /home/uweigand/sandbox/buildbot/clang-s390x-linux-multistage/llvm/include/llvm/ADT/STLExtras.h:875:22:   required from 'decltype (llvm::adl_begin(Range)) llvm::find_if(R&&, UnaryPredicate) [with R = llvm::iterator_range<const clang::CXXBaseSpecifier*>; UnaryPredicate = clang::tidy::bugprone::isParentOf(const clang::CXXRecordDecl&, const clang::CXXRecordDecl&)::<lambda(int&)>; decltype (llvm::adl_begin(Range)) = const clang::CXXBaseSpecifier*]'
> /home/uweigand/sandbox/buildbot/clang-s390x-linux-multistage/llvm/tools/clang/tools/extra/clang-tidy/bugprone/ParentVirtualCallCheck.cpp:34:4:   required from here
> /usr/include/c++/5/bits/predefined_ops.h:234:30: error: no match for call to '(clang::tidy::bugprone::isParentOf(const clang::CXXRecordDecl&, const clang::CXXRecordDecl&)::<lambda(int&)>) (const clang::CXXBaseSpecifier&)'
>   { return bool(_M_pred(*__it)); }
>                               ^
> /home/uweigand/sandbox/buildbot/clang-s390x-linux-multistage/llvm/tools/clang/tools/extra/clang-tidy/bugprone/ParentVirtualCallCheck.cpp:30:73: note: candidate: clang::tidy::bugprone::isParentOf(const clang::CXXRecordDecl&, const clang::CXXRecordDecl&)::<lambda(int&)>
>    const auto ClassIter = llvm::find_if(ThisClass.bases(), [=](auto &Base) {
>                                                                          ^
> /home/uweigand/sandbox/buildbot/clang-s390x-linux-multistage/llvm/tools/clang/tools/extra/clang-tidy/bugprone/ParentVirtualCallCheck.cpp:30:73: note:   no known conversion for argument 1 from 'const clang::CXXBaseSpecifier' to 'int&'ninja: build stopped: subcommand failed.
>
> --------------------------------------
>
>
> пн, 9 апр. 2018 г. в 19:43, Alexander Kornienko <alexfh at google.com>:
>
>> On Fri, Apr 6, 2018 at 10:42 PM Zinovy Nis via cfe-commits <
>> cfe-commits at lists.llvm.org> wrote:
>>
>>> Author: zinovy.nis
>>> Date: Fri Apr  6 13:39:23 2018
>>> New Revision: 329452
>>>
>>> URL: http://llvm.org/viewvc/llvm-project?rev=329452&view=rev
>>> Log:
>>> [clang-tidy] Fix compilation for ParentVirtualCallCheck.cpp
>>>
>>>
>>> Modified:
>>>
>>> clang-tools-extra/trunk/clang-tidy/bugprone/ParentVirtualCallCheck.cpp
>>>
>>> Modified:
>>> clang-tools-extra/trunk/clang-tidy/bugprone/ParentVirtualCallCheck.cpp
>>> URL:
>>> http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/bugprone/ParentVirtualCallCheck.cpp?rev=329452&r1=329451&r2=329452&view=diff
>>>
>>> ==============================================================================
>>> ---
>>> clang-tools-extra/trunk/clang-tidy/bugprone/ParentVirtualCallCheck.cpp
>>> (original)
>>> +++
>>> clang-tools-extra/trunk/clang-tidy/bugprone/ParentVirtualCallCheck.cpp Fri
>>> Apr  6 13:39:23 2018
>>> @@ -11,8 +11,8 @@
>>>  #include "clang/AST/ASTContext.h"
>>>  #include "clang/ASTMatchers/ASTMatchFinder.h"
>>>  #include "clang/Tooling/FixIt.h"
>>> -#include "llvm/ADT/STLExtras.h"
>>>  #include "llvm/ADT/SmallVector.h"
>>> +#include <algorithm>
>>>  #include <cctype>
>>>
>>>  using namespace clang::ast_matchers;
>>> @@ -27,11 +27,13 @@ static bool isParentOf(const CXXRecordDe
>>>                         const CXXRecordDecl &ThisClass) {
>>>    if (Parent.getCanonicalDecl() == ThisClass.getCanonicalDecl())
>>>      return true;
>>> -  const auto ClassIter = llvm::find_if(ThisClass.bases(), [=](auto
>>> &Base) {
>>> -    auto *BaseDecl = Base.getType()->getAsCXXRecordDecl();
>>> -    assert(BaseDecl);
>>> -    return Parent.getCanonicalDecl() == BaseDecl->getCanonicalDecl();
>>> -  });
>>> +  const auto ClassIter = std::find_if(
>>>
>>
>> So what was wrong with llvm::find_if? Why didn't it work here?
>>
>>
>>> +      ThisClass.bases().begin(), ThisClass.bases().end(),
>>> +      [=](const CXXBaseSpecifier &Base) {
>>> +        auto *BaseDecl = Base.getType()->getAsCXXRecordDecl();
>>> +        assert(BaseDecl);
>>> +        return Parent.getCanonicalDecl() ==
>>> BaseDecl->getCanonicalDecl();
>>> +      });
>>>    return ClassIter != ThisClass.bases_end();
>>>  }
>>>
>>> @@ -74,7 +76,8 @@ static std::string getNameAsString(const
>>>  static std::string getExprAsString(const clang::Expr &E,
>>>                                     clang::ASTContext &AC) {
>>>    std::string Text = tooling::fixit::getText(E, AC).str();
>>> -  Text.erase(llvm::remove_if(Text, std::isspace), Text.end());
>>> +  Text.erase(std::remove_if(Text.begin(), Text.end(), std::isspace),
>>> +             Text.end());
>>>    return Text;
>>>  }
>>>
>>>
>>>
>>> _______________________________________________
>>> cfe-commits mailing list
>>> cfe-commits at lists.llvm.org
>>> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
>>>
>>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180410/c3dce6f8/attachment-0001.html>


More information about the cfe-commits mailing list