public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/113407] New: internal_error with const char* as non-type template parameter with index parameter pack in fold expression
@ 2024-01-15 20:25 miro.palmu at helsinki dot fi
2024-01-15 20:33 ` [Bug c++/113407] [11/12/13/14 Regression] " pinskia at gcc dot gnu.org
2024-01-16 8:05 ` rguenth at gcc dot gnu.org
0 siblings, 2 replies; 3+ messages in thread
From: miro.palmu at helsinki dot fi @ 2024-01-15 20:25 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113407
Bug ID: 113407
Summary: internal_error with const char* as non-type template
parameter with index parameter pack in fold expression
Product: gcc
Version: 14.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: miro.palmu at helsinki dot fi
Target Milestone: ---
Created attachment 57093
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=57093&action=edit
The preprocessed source from -freport-bug
I have piece of code that should not compile due to parameter pack not located
at the end of template parameter list. However gcc 14.0.1 20240115 gives
internal compiler error while gcc 13 and earlier do not give internal errors
and the compilation fails gracefully.
Here is the code:
```
// index_sequence implementation:
template <int...> struct index_sequence;
template <int... I>
struct index_sequence{ };
template <int... I>
struct index_sequence_helper;
template <int... I>
struct index_sequence_helper <0, I...> {
using type = index_sequence<I...>;
};
template <int n, int... I>
struct index_sequence_helper <n, I...> : public index_sequence_helper<n - 1, n
- 1, I...> { };
template <int n>
auto make_index_sequence() -> index_sequence_helper<n>::type {};
// Helpers:
template <typename... T, int I>
void inner_func(char) {}
template <typename... T, int I>
struct Foo {};
constexpr char global_string[] = "abc";
template<const char * C, typename... A>
bool func() {
return []<int... I>(index_sequence<I...>) {
return (inner_func<Foo<A..., I>>(C[I]), ...);
}(make_index_sequence<sizeof...(A)>{});
}
int main() {
func<global_string>();
}
```
It also seems that the const char* being non-type template parameter and not a
normal function parameter is important for the internal_error.
Here is the error message (compile command: g++ error.cpp):
```
error.cpp:19:31: error: need ‘typename’ before ‘index_sequence_helper<n>::type’
because ‘index_sequence_helper<n>’ is a dependent scope
19 | auto make_index_sequence() -> index_sequence_helper<n>::type {};
| ^~~~~~~~~~~~~~~~~~~~~~~~
| typename
error.cpp:26:11: error: parameter pack ‘T’ must be at the end of the template
parameter list
26 | template <typename... T, int I>
| ^~~~~~~~
error.cpp: In lambda function:
error.cpp:35:38: note: so any instantiation with a non-empty parameter pack
would be ill-formed
35 | return (inner_func<Foo<A..., I>>(C[I]), ...);
| ^
error.cpp: In function ‘bool func()’:
error.cpp:36:7: error: ‘make_index_sequence’ was not declared in this scope;
did you mean ‘index_sequence’?
36 | }(make_index_sequence<sizeof...(A)>{});
| ^~~~~~~~~~~~~~~~~~~
| index_sequence
error.cpp:36:40: error: expected primary-expression before ‘{’ token
36 | }(make_index_sequence<sizeof...(A)>{});
| ^
error.cpp: In instantiation of ‘bool func() [with const char* C = (&
global_string); A = {}]’:
error.cpp:40:24: required from here
error.cpp:36:40: error: 40 | func<global_string>();
error.cpp:36:40: error: | ~~~~~~~~~~~~~~~~~~~^~
error.cpp:35:47: internal compiler error: tree check: expected
type_pack_expansion or expr_pack_expansion, have error_mark in
tsubst_pack_expansion, at cp/pt.cc:13632
35 | return (inner_func<Foo<A..., I>>(C[I]), ...);
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~
0x951506 tree_check_failed(tree_node const*, char const*, int, char const*,
...)
.././../gcc/tree.cc:8952
0x7edbaf tree_check2(tree_node*, char const*, int, char const*, tree_code,
tree_code)
.././../gcc/tree.h:3631
0x7edbaf tsubst_pack_expansion(tree_node*, tree_node*, int, tree_node*)
.././../gcc/cp/pt.cc:13632
0xc784c4 tsubst_fold_expr_pack
.././../gcc/cp/pt.cc:13043
0xc784c4 tsubst_unary_right_fold
.././../gcc/cp/pt.cc:13159
0xc5994a tsubst_expr(tree_node*, tree_node*, int, tree_node*)
.././../gcc/cp/pt.cc:21547
0xc68147 tsubst_stmt
.././../gcc/cp/pt.cc:19384
0xc69108 tsubst_stmt
.././../gcc/cp/pt.cc:18351
0xc68d72 tsubst_stmt
.././../gcc/cp/pt.cc:18714
0xc7e4d0 tsubst_stmt
.././../gcc/cp/pt.cc:18327
0xc7e4d0 tsubst_lambda_expr(tree_node*, tree_node*, int, tree_node*)
.././../gcc/cp/pt.cc:19732
0xc5b944 tsubst_expr(tree_node*, tree_node*, int, tree_node*)
.././../gcc/cp/pt.cc:21629
0xc58482 tsubst_expr(tree_node*, tree_node*, int, tree_node*)
.././../gcc/cp/pt.cc:20670
0xc68147 tsubst_stmt
.././../gcc/cp/pt.cc:19384
0xc69108 tsubst_stmt
.././../gcc/cp/pt.cc:18351
0xc6918f tsubst_stmt
.././../gcc/cp/pt.cc:18327
0xc6918f tsubst_stmt
.././../gcc/cp/pt.cc:18341
0xc68d72 tsubst_stmt
.././../gcc/cp/pt.cc:18714
0xc66ea2 tsubst_stmt
.././../gcc/cp/pt.cc:18327
0xc66ea2 instantiate_body
.././../gcc/cp/pt.cc:26974
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.
```
^ permalink raw reply [flat|nested] 3+ messages in thread
* [Bug c++/113407] [11/12/13/14 Regression] internal_error with const char* as non-type template parameter with index parameter pack in fold expression
2024-01-15 20:25 [Bug c++/113407] New: internal_error with const char* as non-type template parameter with index parameter pack in fold expression miro.palmu at helsinki dot fi
@ 2024-01-15 20:33 ` pinskia at gcc dot gnu.org
2024-01-16 8:05 ` rguenth at gcc dot gnu.org
1 sibling, 0 replies; 3+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-01-15 20:33 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113407
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Last reconfirmed| |2024-01-15
Known to work| |11.1.0
Known to fail| |11.2.0
Ever confirmed|0 |1
Status|UNCONFIRMED |NEW
Severity|normal |trivial
Summary|internal_error with const |[11/12/13/14 Regression]
|char* as non-type template |internal_error with const
|parameter with index |char* as non-type template
|parameter pack in fold |parameter with index
|expression |parameter pack in fold
| |expression
Target Milestone|--- |11.5
--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Confirmed.
Looks like the code which crashes:
PACK_EXPANSION_LOCAL_P (result) = PACK_EXPANSION_LOCAL_P (t);
PACK_EXPANSION_SIZEOF_P (result) = PACK_EXPANSION_SIZEOF_P (t);
was added with r12-701-ge7a9f085ffd34b0d7bc4b803c182b41 .
Note GCC 12+/11.2.0 will crash too if checking is enabled.
^ permalink raw reply [flat|nested] 3+ messages in thread
* [Bug c++/113407] [11/12/13/14 Regression] internal_error with const char* as non-type template parameter with index parameter pack in fold expression
2024-01-15 20:25 [Bug c++/113407] New: internal_error with const char* as non-type template parameter with index parameter pack in fold expression miro.palmu at helsinki dot fi
2024-01-15 20:33 ` [Bug c++/113407] [11/12/13/14 Regression] " pinskia at gcc dot gnu.org
@ 2024-01-16 8:05 ` rguenth at gcc dot gnu.org
1 sibling, 0 replies; 3+ messages in thread
From: rguenth at gcc dot gnu.org @ 2024-01-16 8:05 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113407
Richard Biener <rguenth at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Priority|P3 |P4
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2024-01-16 8:05 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-01-15 20:25 [Bug c++/113407] New: internal_error with const char* as non-type template parameter with index parameter pack in fold expression miro.palmu at helsinki dot fi
2024-01-15 20:33 ` [Bug c++/113407] [11/12/13/14 Regression] " pinskia at gcc dot gnu.org
2024-01-16 8:05 ` rguenth at gcc dot gnu.org
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).