[PATCH] D18061: Add iterator types to iterator_range, to appease newer gcc's

Dimitry Andric via llvm-commits llvm-commits at lists.llvm.org
Fri Mar 11 11:43:25 PST 2016


dim added a comment.

As an example, I reduced the code included from CFG.cpp into F1631241: reduced-reverse.cpp <http://reviews.llvm.org/F1631241>.  This reduced sample will define `iterator_range::iterator` and `iterator_range::const_iterator` when `DEFINE_ITERATORS` is defined.

When you compile F1631241: reduced-reverse.cpp <http://reviews.llvm.org/F1631241> using clang and libc++, it is all OK.  When you compile it with gcc (I used 5.3.0) and its default libstdc++, it is also OK.  However, when you compile it with gcc 5.3.0 and libc++ (the version in the FreeBSD base system, at least), you get this mess:

  $ gcc5 -std=c++11 -I/usr/include/c++/v1 -c reduced-reverse.cpp
  reduced-reverse.cpp: In function 'void buildCFG(CXXConstructorDecl*)':
  reduced-reverse.cpp:126:43: error: no matching function for call to 'reverse(CXXConstructorDecl::init_range)'
     for (auto *I : llvm::reverse(CD->inits())) {
                                             ^
  reduced-reverse.cpp:70:6: note: candidate: template<class ContainerTy> decltype (llvm::make_range(C.rbegin(), C.rend())) llvm::reverse(ContainerTy&&, typename std::__1::enable_if<llvm::has_rbegin<ContainerTy>::value>::type*)
   auto reverse(ContainerTy &&C,
        ^
  reduced-reverse.cpp:70:6: note:   template argument deduction/substitution failed:
  reduced-reverse.cpp: In substitution of 'template<class ContainerTy> decltype (llvm::make_range(C.rbegin(), C.rend())) llvm::reverse(ContainerTy&&, typename std::__1::enable_if<llvm::has_rbegin<ContainerTy>::value>::type*) [with ContainerTy = llvm::iterator_range<CXXConstructorDecl**>]':
  reduced-reverse.cpp:126:43:   required from here
  reduced-reverse.cpp:70:6: error: no type named 'type' in 'struct std::__1::enable_if<false, void>'
  reduced-reverse.cpp:86:6: note: candidate: template<class ContainerTy> decltype (llvm::make_range(llvm::make_reverse_iterator(std::__1::end(C)), llvm::make_reverse_iterator(std::__1::begin(C)))) llvm::reverse(ContainerTy&&, typename std::__1::enable_if<(! llvm::has_rbegin<ContainerTy>::value)>::type*)
   auto reverse(
        ^
  reduced-reverse.cpp:86:6: note:   template argument deduction/substitution failed:
  reduced-reverse.cpp: In substitution of 'template<class ContainerTy> decltype (llvm::make_range(llvm::make_reverse_iterator(std::__1::end(C)), llvm::make_reverse_iterator(std::__1::begin(C)))) llvm::reverse(ContainerTy&&, typename std::__1::enable_if<(! llvm::has_rbegin<ContainerTy>::value)>::type*) [with ContainerTy = llvm::iterator_range<CXXConstructorDecl**>]':
  reduced-reverse.cpp:126:43:   required from here
  reduced-reverse.cpp:89:64: error: no matching function for call to 'end(llvm::iterator_range<CXXConstructorDecl**>&)'
       -> decltype(make_range(llvm::make_reverse_iterator(std::end(C)),
                                                                  ^
  In file included from /usr/include/c++/v1/iterator:347:0,
                   from reduced-reverse.cpp:1:
  /usr/include/c++/v1/initializer_list:109:1: note: candidate: template<class _Ep> const _Ep* std::end(std::initializer_list<_Ep>)
   end(initializer_list<_Ep> __il) _NOEXCEPT
   ^
  /usr/include/c++/v1/initializer_list:109:1: note:   template argument deduction/substitution failed:
  reduced-reverse.cpp:89:64: note:   'llvm::iterator_range<CXXConstructorDecl**>' is not derived from 'std::initializer_list<_Ep>'
       -> decltype(make_range(llvm::make_reverse_iterator(std::end(C)),
                                                                  ^
  In file included from reduced-reverse.cpp:1:0:
  /usr/include/c++/v1/iterator:1575:1: note: candidate: template<class _Cp> typename _Cp::const_iterator std::__1::end(const _Cp&)
   end(const _Cp& __c)
   ^
  /usr/include/c++/v1/iterator:1575:1: note:   template argument deduction/substitution failed:
  /usr/include/c++/v1/iterator: In substitution of 'template<class _Cp> typename _Cp::const_iterator std::__1::end(const _Cp&) [with _Cp = llvm::iterator_range<CXXConstructorDecl**>]':
  reduced-reverse.cpp:89:64:   required by substitution of 'template<class ContainerTy> decltype (llvm::make_range(llvm::make_reverse_iterator(std::__1::end(C)), llvm::make_reverse_iterator(std::__1::begin(C)))) llvm::reverse(ContainerTy&&, typename std::__1::enable_if<(! llvm::has_rbegin<ContainerTy>::value)>::type*) [with ContainerTy = llvm::iterator_range<CXXConstructorDecl**>]'
  reduced-reverse.cpp:126:43:   required from here
  /usr/include/c++/v1/iterator:1575:1: error: no type named 'const_iterator' in 'class llvm::iterator_range<CXXConstructorDecl**>'
  reduced-reverse.cpp: In substitution of 'template<class ContainerTy> decltype (llvm::make_range(llvm::make_reverse_iterator(std::__1::end(C)), llvm::make_reverse_iterator(std::__1::begin(C)))) llvm::reverse(ContainerTy&&, typename std::__1::enable_if<(! llvm::has_rbegin<ContainerTy>::value)>::type*) [with ContainerTy = llvm::iterator_range<CXXConstructorDecl**>]':
  reduced-reverse.cpp:126:43:   required from here
  /usr/include/c++/v1/iterator:1567:1: note: candidate: template<class _Cp> typename _Cp::iterator std::__1::end(_Cp&)
   end(_Cp& __c)
   ^
  /usr/include/c++/v1/iterator:1567:1: note:   template argument deduction/substitution failed:
  /usr/include/c++/v1/iterator: In substitution of 'template<class _Cp> typename _Cp::iterator std::__1::end(_Cp&) [with _Cp = llvm::iterator_range<CXXConstructorDecl**>]':
  reduced-reverse.cpp:89:64:   required by substitution of 'template<class ContainerTy> decltype (llvm::make_range(llvm::make_reverse_iterator(std::__1::end(C)), llvm::make_reverse_iterator(std::__1::begin(C)))) llvm::reverse(ContainerTy&&, typename std::__1::enable_if<(! llvm::has_rbegin<ContainerTy>::value)>::type*) [with ContainerTy = llvm::iterator_range<CXXConstructorDecl**>]'
  reduced-reverse.cpp:126:43:   required from here
  /usr/include/c++/v1/iterator:1567:1: error: no type named 'iterator' in 'class llvm::iterator_range<CXXConstructorDecl**>'
  reduced-reverse.cpp: In substitution of 'template<class ContainerTy> decltype (llvm::make_range(llvm::make_reverse_iterator(std::__1::end(C)), llvm::make_reverse_iterator(std::__1::begin(C)))) llvm::reverse(ContainerTy&&, typename std::__1::enable_if<(! llvm::has_rbegin<ContainerTy>::value)>::type*) [with ContainerTy = llvm::iterator_range<CXXConstructorDecl**>]':
  reduced-reverse.cpp:126:43:   required from here
  /usr/include/c++/v1/iterator:1418:1: note: candidate: template<class _Tp, long unsigned int _Np> _Tp* std::__1::end(_Tp (&)[_Np])
   end(_Tp (&__array)[_Np])
   ^
  /usr/include/c++/v1/iterator:1418:1: note:   template argument deduction/substitution failed:
  reduced-reverse.cpp:89:64: note:   mismatched types '_Tp [_Np]' and 'llvm::iterator_range<CXXConstructorDecl**>'
       -> decltype(make_range(llvm::make_reverse_iterator(std::end(C)),
                                                                  ^
  reduced-reverse.cpp:90:66: error: no matching function for call to 'begin(llvm::iterator_range<CXXConstructorDecl**>&)'
                              llvm::make_reverse_iterator(std::begin(C)))) {
                                                                    ^
  In file included from /usr/include/c++/v1/iterator:347:0,
                   from reduced-reverse.cpp:1:
  /usr/include/c++/v1/initializer_list:100:1: note: candidate: template<class _Ep> const _Ep* std::begin(std::initializer_list<_Ep>)
   begin(initializer_list<_Ep> __il) _NOEXCEPT
   ^
  /usr/include/c++/v1/initializer_list:100:1: note:   template argument deduction/substitution failed:
  reduced-reverse.cpp:90:66: note:   'llvm::iterator_range<CXXConstructorDecl**>' is not derived from 'std::initializer_list<_Ep>'
                              llvm::make_reverse_iterator(std::begin(C)))) {
                                                                    ^
  In file included from reduced-reverse.cpp:1:0:
  /usr/include/c++/v1/iterator:1559:1: note: candidate: template<class _Cp> typename _Cp::const_iterator std::__1::begin(const _Cp&)
   begin(const _Cp& __c)
   ^
  /usr/include/c++/v1/iterator:1559:1: note:   template argument deduction/substitution failed:
  /usr/include/c++/v1/iterator: In substitution of 'template<class _Cp> typename _Cp::const_iterator std::__1::begin(const _Cp&) [with _Cp = llvm::iterator_range<CXXConstructorDecl**>]':
  reduced-reverse.cpp:90:66:   required by substitution of 'template<class ContainerTy> decltype (llvm::make_range(llvm::make_reverse_iterator(std::__1::end(C)), llvm::make_reverse_iterator(std::__1::begin(C)))) llvm::reverse(ContainerTy&&, typename std::__1::enable_if<(! llvm::has_rbegin<ContainerTy>::value)>::type*) [with ContainerTy = llvm::iterator_range<CXXConstructorDecl**>]'
  reduced-reverse.cpp:126:43:   required from here
  /usr/include/c++/v1/iterator:1559:1: error: no type named 'const_iterator' in 'class llvm::iterator_range<CXXConstructorDecl**>'
  reduced-reverse.cpp: In substitution of 'template<class ContainerTy> decltype (llvm::make_range(llvm::make_reverse_iterator(std::__1::end(C)), llvm::make_reverse_iterator(std::__1::begin(C)))) llvm::reverse(ContainerTy&&, typename std::__1::enable_if<(! llvm::has_rbegin<ContainerTy>::value)>::type*) [with ContainerTy = llvm::iterator_range<CXXConstructorDecl**>]':
  reduced-reverse.cpp:126:43:   required from here
  /usr/include/c++/v1/iterator:1551:1: note: candidate: template<class _Cp> typename _Cp::iterator std::__1::begin(_Cp&)
   begin(_Cp& __c)
   ^
  /usr/include/c++/v1/iterator:1551:1: note:   template argument deduction/substitution failed:
  /usr/include/c++/v1/iterator: In substitution of 'template<class _Cp> typename _Cp::iterator std::__1::begin(_Cp&) [with _Cp = llvm::iterator_range<CXXConstructorDecl**>]':
  reduced-reverse.cpp:90:66:   required by substitution of 'template<class ContainerTy> decltype (llvm::make_range(llvm::make_reverse_iterator(std::__1::end(C)), llvm::make_reverse_iterator(std::__1::begin(C)))) llvm::reverse(ContainerTy&&, typename std::__1::enable_if<(! llvm::has_rbegin<ContainerTy>::value)>::type*) [with ContainerTy = llvm::iterator_range<CXXConstructorDecl**>]'
  reduced-reverse.cpp:126:43:   required from here
  /usr/include/c++/v1/iterator:1551:1: error: no type named 'iterator' in 'class llvm::iterator_range<CXXConstructorDecl**>'
  reduced-reverse.cpp: In substitution of 'template<class ContainerTy> decltype (llvm::make_range(llvm::make_reverse_iterator(std::__1::end(C)), llvm::make_reverse_iterator(std::__1::begin(C)))) llvm::reverse(ContainerTy&&, typename std::__1::enable_if<(! llvm::has_rbegin<ContainerTy>::value)>::type*) [with ContainerTy = llvm::iterator_range<CXXConstructorDecl**>]':
  reduced-reverse.cpp:126:43:   required from here
  /usr/include/c++/v1/iterator:1410:1: note: candidate: template<class _Tp, long unsigned int _Np> _Tp* std::__1::begin(_Tp (&)[_Np])
   begin(_Tp (&__array)[_Np])
   ^
  /usr/include/c++/v1/iterator:1410:1: note:   template argument deduction/substitution failed:
  reduced-reverse.cpp:90:66: note:   mismatched types '_Tp [_Np]' and 'llvm::iterator_range<CXXConstructorDecl**>'
                              llvm::make_reverse_iterator(std::begin(C)))) {
                                                                    ^


http://reviews.llvm.org/D18061





More information about the llvm-commits mailing list