Bug 112633 - [13/14 Regression] ICE with type aliases and depedent value
Summary: [13/14 Regression] ICE with type aliases and depedent value
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 13.1.0
: P3 normal
Target Milestone: 13.3
Assignee: Patrick Palka
URL:
Keywords: ice-on-valid-code
Depends on:
Blocks:
 
Reported: 2023-11-20 06:27 UTC by Hana Dusíková
Modified: 2023-11-27 22:19 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2023-11-20 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Hana Dusíková 2023-11-20 06:27:42 UTC
Tested on GCC 14.0.0 20231119 (on Compiler-Explorer) and it's giving me ICE, also on all 13.x versions (not 12.x)

```c++
template <class> constexpr bool dependent_true = true;

template <bool> struct empty_type { }; // something like enable_if

template <bool B> using empty_type_t = typename empty_type<B>::type; 

struct wrapper {
    using type = void;
};

template <class...> using all = wrapper;

template <class... Conditions>
using constraints = typename all<Conditions...>::type;

template <typename T, constraints<empty_type_t<dependent_true<T>>> = nullptr> 
void calculate() { };
```

I don't even need to instantiate `calculate` function.

It gives me this error:

<source>: In substitution of 'template<class ... Conditions> using constraints = typename all<Conditions ...>::type [with Conditions = {typename empty_type<dependent_true<T> >::type}]':
<source>:16:66:   required from here
   16 | template <typename T, constraints<empty_type_t<dependent_true<T>>> = nullptr>
      |                                                                  ^
<source>:14:7: internal compiler error: Segmentation fault
   14 | using constraints = typename all<Conditions...>::type;
      |       ^~~~~~~~~~~
0x26a742e internal_error(char const*, ...)
	???:0
0xd276f0 tsubst(tree_node*, tree_node*, int, tree_node*)
	???:0
0xd1b8f3 instantiate_template(tree_node*, tree_node*, int)
	???:0
0xd285ea tsubst(tree_node*, tree_node*, int, tree_node*)
	???:0
0xd35ed6 lookup_template_class(tree_node*, tree_node*, tree_node*, tree_node*, int, int)
	???:0
0xd6996f finish_template_type(tree_node*, tree_node*, int)
	???:0
0xcf6a49 c_parse_file()
	???:0
0xe38e79 c_common_parse_file()
	???:0
Please submit a full bug report, with preprocessed source (by using -freport-bug).
Please include the complete backtrace with any bug report.
See <https://gcc.gnu.org/bugs/> for instructions.
Compiler returned: 1
Comment 1 Andrew Pinski 2023-11-20 06:47:38 UTC
Confirmed, note this is not related to variadic templates as this crashes in a similar way:
```
template <class> constexpr bool dependent_true = true;

template <bool> struct empty_type { }; // something like enable_if

template <bool B> using empty_type_t = typename empty_type<B>::type; 

struct wrapper {
    using type = void;
};

template <class> using all = wrapper;

template <class Conditions>
using constraints = typename all<Conditions>::type;

template <typename T, constraints<empty_type_t<dependent_true<T>>> = nullptr> 
void calculate() { };
```
Comment 2 Andrew Pinski 2023-11-20 06:47:58 UTC
.
Comment 3 Patrick Palka 2023-11-20 14:31:46 UTC
Started with r13-4729-gbe124477b38a71
Comment 4 GCC Commits 2023-11-22 18:54:54 UTC
The master branch has been updated by Patrick Palka <ppalka@gcc.gnu.org>:

https://gcc.gnu.org/g:3f266c84a15d63e42bfad46397fea9aff92b0720

commit r14-5763-g3f266c84a15d63e42bfad46397fea9aff92b0720
Author: Patrick Palka <ppalka@redhat.com>
Date:   Wed Nov 22 13:54:29 2023 -0500

    c++: alias template of non-template class [PR112633]
    
    The entering_scope adjustment in tsubst_aggr_type assumes if an alias is
    dependent, then so is the aliased type (and therefore it has template info)
    but that's not true for the dependent alias template specialization ty1<T>
    below which aliases the non-template class A.  In this case no adjustment
    is needed anyway, so we can just punt.
    
            PR c++/112633
    
    gcc/cp/ChangeLog:
    
            * pt.cc (tsubst_aggr_type): Handle empty TYPE_TEMPLATE_INFO
            in the entering_scope adjustment.
    
    gcc/testsuite/ChangeLog:
    
            * g++.dg/cpp0x/alias-decl-75.C: New test.
Comment 5 Hana Dusíková 2023-11-22 19:11:52 UTC
Thanks for really quick fix! You are awesome!
Comment 6 GCC Commits 2023-11-23 00:08:18 UTC
The releases/gcc-13 branch has been updated by Patrick Palka <ppalka@gcc.gnu.org>:

https://gcc.gnu.org/g:63c65224e778124eee52acc7b9fcb32cd8ad61e8

commit r13-8090-g63c65224e778124eee52acc7b9fcb32cd8ad61e8
Author: Patrick Palka <ppalka@redhat.com>
Date:   Wed Nov 22 19:07:19 2023 -0500

    c++: alias template of non-template class [PR112633]
    
    The entering_scope adjustment in tsubst_aggr_type assumes if an alias is
    dependent, then so is the aliased type (and therefore it has template info)
    but that's not true for the dependent alias template specialization ty1<T>
    below which aliases the non-template class A.  In this case no adjustment
    is needed anyway, so we can just punt.
    
            PR c++/112633
    
    gcc/cp/ChangeLog:
    
            * pt.cc (tsubst_aggr_type): Handle empty TYPE_TEMPLATE_INFO
            in the entering_scope adjustment.
    
    gcc/testsuite/ChangeLog:
    
            * g++.dg/cpp0x/alias-decl-75.C: New test.
    
    (cherry picked from commit 3f266c84a15d63e42bfad46397fea9aff92b0720)
Comment 7 Patrick Palka 2023-11-27 22:19:44 UTC
Fixed for GCC 13.3, thanks for the bug report.