[clang] [clang][ASTImporter] Fix possible crash "given incorrect InsertPos for specialization". (PR #89887)
Balázs Kéri via cfe-commits
cfe-commits at lists.llvm.org
Wed Apr 24 01:00:52 PDT 2024
balazske wrote:
A test is needed to make the change acceptable but I could not find an easy case to provoke the situation. The problem looks to be related to his code:
```c++
using size_t = int;
template<typename... _Types> class tuple;
template<class T, T v>
struct integral_constant
{
static constexpr T value = v;
using value_type = T;
using type = integral_constant; // using injected-class-name
constexpr operator value_type() const noexcept { return value; }
constexpr value_type operator()() const noexcept { return value; } // since c++14
};
using true_type = integral_constant<bool, true>;
using false_type = integral_constant<bool, false>;
template<class T, class U>
struct is_same : false_type {};
template<class T>
struct is_same<T, T> : true_type {};
template< class T, class U >
inline constexpr bool is_same_v = is_same<T, U>::value;
namespace A {
template<typename _Tp, typename _Tuple>
struct __tuple_count;
template<typename _Tp, typename _Tuple>
inline constexpr size_t __tuple_count_v =
__tuple_count<_Tp, _Tuple>::value;
template<typename _Tp, typename... _Types>
struct __tuple_count<_Tp, tuple<_Types...>>
: integral_constant<size_t, 0> { };
template<typename _Tp, typename _First, typename... _Rest>
struct __tuple_count<_Tp, tuple<_First, _Rest...>>
: integral_constant<
size_t,
__tuple_count_v<_Tp, tuple<_Rest...>> + is_same_v<_Tp, _First>> { };
};
size_t x = A::__tuple_count_v<int, tuple<bool, int, float>>;
```
https://github.com/llvm/llvm-project/pull/89887
More information about the cfe-commits
mailing list