[clang] [clang][ASTImporter] Fix possible crash "given incorrect InsertPos for specialization". (PR #89887)
Qizhi Hu via cfe-commits
cfe-commits at lists.llvm.org
Thu May 23 23:11:37 PDT 2024
jcsxky 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>>;
> ```
Could you please show your commands which reproduced this crash? I tested locally with the following commands and it runs OK.
```cpp
clang++ -cc1 -std=c++17 -emit-pch -o test.cpp.ast test.cpp
clang++ -cc1 -x c++ -ast-merge test.cpp.ast /dev/null -ast-dump
```
https://github.com/llvm/llvm-project/pull/89887
More information about the cfe-commits
mailing list