Skip to content

Commit fdebe70

Browse files
gwllxnv-cmeerw
authored andcommitted
Fix crash in alias template CTAD with a template-id in a constructor noexcept [GH #532]
1 parent cb7d105 commit fdebe70

7 files changed

Lines changed: 45 additions & 3 deletions

File tree

‎src/expr.c‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54900,8 +54900,10 @@ is TRUE if the expression is the immediate operand of an "&" operator.
5490054900
} /* if */
5490154901
} else if (is_nontype_template_param_symbol(fund_sym)) {
5490254902
/* A dependent construct. Represent it generically with a
54903-
tpck_template_ref constant. */
54904-
expl_templ_arg_list =
54903+
tpck_template_ref constant. Leave expl_templ_arg_list
54904+
unsubstituted, since scan_identifier will also substitute
54905+
it. */
54906+
a_template_arg_ptr subst_templ_arg_list =
5490554907
copy_template_arg_list_with_substitution_rebuilding_arg_operands(
5490654908
fund_sym, expl_templ_arg_list,
5490754909
(a_template_param_ptr)NULL,
@@ -54916,7 +54918,7 @@ is TRUE if the expression is the immediate operand of an "&" operator.
5491654918
con->variant.template_param.variant.template_ref.con =
5491754919
sym->variant.constant;
5491854920
con->variant.template_param.variant.template_ref.arg_list =
54919-
expl_templ_arg_list;
54921+
subst_templ_arg_list;
5492054922
con->type = type_of_unknown_templ_param_nontype;
5492154923
sym = alloc_symbol(sk_constant, sym->header,
5492254924
&sym->decl_position);
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
[GH #532]
2+
Alias template CTAD with a template-id in a constructor noexcept specification
3+
4+
Class template argument deduction through an alias template could crash
5+
when the noexcept specification of a constructor template of the underlying
6+
class template called a member function template with the constructor's
7+
template parameter pack as explicit template arguments, e.g. aliases of
8+
std::tuple with libstdc++. The explicit template arguments were substituted
9+
twice. For example, with --c++20:
10+
11+
template<typename... E> struct S {
12+
template<typename... U> static constexpr bool n() { return true; }
13+
S(const E&...) {}
14+
template<typename... U> S(U&&...) noexcept(n<U...>()) {}
15+
};
16+
template<typename X, typename T> struct F {};
17+
template<typename X, typename... T> using A = S<F<X, T>...>;
18+
A a{F<int, int>{}};
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
fe_only -DTEST_NUMBER=1 --c++20 Test_name.c
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
fe_only -DTEST_NUMBER=2 --c++20 --g++ --gnu_version=150200 Test_name.c
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
fe_only -DTEST_NUMBER=3 --c++20 --clang --clang_version=220100 Test_name.c
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
fe_only -DTEST_NUMBER=4 --ms_c++20 --microsoft_version 1950 Test_name.c
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
//type:fp
2+
//options:--c++20:--c++20 --g++ --gnu_version=150200:--c++20 --clang --clang_version=220100:--ms_c++20 --microsoft_version 1950
3+
4+
// Class template argument deduction through an alias template crashed when
5+
// the noexcept specification of a constructor template called a member
6+
// function template with the constructor's parameter pack as explicit
7+
// template arguments, e.g. aliases of std::tuple with libstdc++. The
8+
// explicit template arguments of the call were substituted twice.
9+
10+
template<typename... E> struct S
11+
{
12+
template<typename... U> static constexpr bool n() { return true; }
13+
S(const E&...) {}
14+
template<typename... U> S(U&&...) noexcept(n<U...>()) {}
15+
};
16+
template<typename X, typename T> struct F {};
17+
template<typename X, typename... T> using A = S<F<X, T>...>;
18+
A a{F<int, int>{}};

0 commit comments

Comments
 (0)