Skip to content

Commit

Permalink
Fix build when compiling against libc++ (#5284)
Browse files Browse the repository at this point in the history
When using libc++, the build fails with errors like:

 error: incomplete type 'clang::DeclContext::udir_iterator' used in type trait expression
    : public integral_constant<bool, __is_base_of(_Bp, _Dp)> {};
                                                          ^
 note: while substituting deduced template arguments into function template 'iterator_adaptor_base' [with U = const llvm::iterator_adaptor_base<clang::DeclContext::udir_iterator, clang::DeclContextLookupResult::iterator, std::random_access_iterator_tag, clang::UsingDirectiveDecl *> &]
class iterator_adaptor_base

This was fixed in upstream LLVM in this CL:
llvm/llvm-project@e78e32a
(also see original review: https://reviews.llvm.org/D22951#change-zKJSAlLXXy11)
Unfortunately, the CL does not explain why this change was made, so I
can only assume that it was failing a libc++ build as well.

I also added the static_assert that was later added in this CL:
llvm/llvm-project@0aecae3
This restores the build failure that would occur if U is not a base of DerivedT.
  • Loading branch information
amaiorano authored Jun 15, 2023
1 parent 66f8c6d commit 5e080a7
Showing 1 changed file with 6 additions and 9 deletions.
15 changes: 6 additions & 9 deletions include/llvm/ADT/iterator.h
Original file line number Diff line number Diff line change
Expand Up @@ -152,15 +152,12 @@ class iterator_adaptor_base

iterator_adaptor_base() = default;

template <typename U>
explicit iterator_adaptor_base(
U &&u,
typename std::enable_if<
!std::is_base_of<typename std::remove_cv<
typename std::remove_reference<U>::type>::type,
DerivedT>::value,
int>::type = 0)
: I(std::forward<U &&>(u)) {}
// HLSL Change Begins: Fix libc++ build
explicit iterator_adaptor_base(WrappedIteratorT u) : I(std::move(u)) {
static_assert(std::is_base_of<iterator_adaptor_base, DerivedT>::value,
"Must pass the derived type to this template!");
}
// HLSL Change Ends

const WrappedIteratorT &wrapped() const { return I; }

Expand Down

0 comments on commit 5e080a7

Please sign in to comment.