Bug 94100 - ICE: tree check: accessed elt 1 of 'tree_vec' with 0 elts in tsubst_pack_expansion, at cp/pt.c:12765
Summary: ICE: tree check: accessed elt 1 of 'tree_vec' with 0 elts in tsubst_pack_expa...
Status: NEW
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 10.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: ice-on-valid-code
Depends on:
Blocks:
 
Reported: 2020-03-09 12:51 UTC by Jens Kilian
Modified: 2021-08-13 22:51 UTC (History)
4 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2021-08-13 00:00:00


Attachments
Source file to be compiled. (199 bytes, text/plain)
2020-03-09 12:51 UTC, Jens Kilian
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Jens Kilian 2020-03-09 12:51:23 UTC
Created attachment 47998 [details]
Source file to be compiled.

The attached file elicits an ICE in the GCC "trunk" version used by Compiler Explorer (https://godbolt.org/z/iPK_JV):
------------
<source>: In function 'int main()':
<source>:20:24: internal compiler error: tree check: accessed elt 1 of 'tree_vec' with 0 elts in tsubst_pack_expansion, at cp/pt.c:12765
   20 |   Foo<bool>::foo<true>();
      |                        ^
Please submit a full bug report,
with preprocessed source if appropriate.
See <https://gcc.gnu.org/bugs/> for instructions.
------------

When using GCC 9.2, no ICE happens, but the file fails to be parsed:
------------
<source>: In function 'int main()':
<source>:20:24: error: no matching function for call to 'Foo<bool>::foo<true>()'
   20 |   Foo<bool>::foo<true>();
      |                        ^
<source>:11:3: note: candidate: 'template<ARGS ...args> static void Foo<ARGS>::foo() [with ARGS ...args = {args ...}; ARGS = {bool}]'
   11 |   foo(void)
      |   ^~~
<source>:11:3: note:   template argument deduction/substitution failed:
<source>:21:31: error: no matching function for call to 'Foo<int, long int>::foo<42, 23>()'
   21 |   Foo<int, long>::foo<42, 23>();
      |                               ^
<source>:11:3: note: candidate: 'template<ARGS ...args> static void Foo<ARGS>::foo() [with ARGS ...args = {args ...}; ARGS = {int, long int}]'
   11 |   foo(void)
      |   ^~~
<source>:11:3: note:   template argument deduction/substitution failed:
<source>:21:31: error: wrong number of template arguments (2, should be 1)
   21 |   Foo<int, long>::foo<42, 23>();
      |                               ^
<source>:22:34: error: no matching function for call to 'Foo<char, char>::foo<'h', 'i'>()'
   22 |   Foo<char, char>::foo<'h', 'i'>();
      |                                  ^
<source>:11:3: note: candidate: 'template<ARGS ...args> static void Foo<ARGS>::foo() [with ARGS ...args = {args ...}; ARGS = {char, char}]'
   11 |   foo(void)
      |   ^~~
<source>:11:3: note:   template argument deduction/substitution failed:
<source>:22:34: error: wrong number of template arguments (2, should be 1)
   22 |   Foo<char, char>::foo<'h', 'i'>();
      |                                  ^
------------

Clang correctly compiles the file.
Comment 1 Marek Polacek 2020-03-09 14:24:41 UTC
The ICE started with r0-128638-gb0ff7fe1d223260aea5b7dc3f36892aa57d43c77 -- a while ago.  Before that:

94100.C:19:24: error: no matching function for call to ‘Foo<bool>::foo()’
   Foo<bool>::foo<true>();
                        ^
Comment 2 Hubert Tong 2020-07-02 23:12:41 UTC
The following ICEs in a similar fashion:
internal compiler error: tree check: accessed elt 2 of 'tree_vec' with 1 elts in tsubst, at cp/pt.c:15334

### SOURCE:
template <typename... T> struct ValListWithTypes {
  template <T... Members> struct WithVals {
    using TypeList = ValListWithTypes;
  };
};

template <typename ValList, typename ValTypeList = typename ValList::TypeList>
struct Widget;

template <typename ValList, typename... ValTypes>
struct Widget<ValList, ValListWithTypes<ValTypes...>> {
  template <typename = ValList> struct Impl {};
};

template <typename ValList, typename... ValTypes>
template <ValTypes... Vals>
struct Widget<ValList, ValListWithTypes<ValTypes...>>::Impl<
    typename ValListWithTypes<ValTypes...>::template WithVals<Vals...>> {};

int main(void) { Widget<ValListWithTypes<int>::WithVals<0>>::Impl<> impl; }