https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100764
Bug ID: 100764
Summary: Internal compiler error when unable to deduce template
parameter value
Product: gcc
Version: 11.1.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: egor_suvorov at mail dot ru
Target Milestone: ---
The following snippet, when compiled with `g++ -std=c++20`:
template <int N>
struct LiteralResolver {
constexpr LiteralResolver(const char (&text)[N]) {
}
using type = int;
};
template <LiteralResolver Resolve>
using q_literal_type = decltype(Resolve)::type;
template <LiteralResolver Resolve>
q_literal_type<Resolve> operator""_q() {
}
int main() {
"hello"_q;
}
yields the following error message with GCC 11.1 and GCC trunk on Godbolt
(https://godbolt.org/z/jnffoTvao):
'
Internal compiler error: Error reporting routines re-entered.
0x17802b1 warning(int, char const*, ...)
???:0
0x7d4077 do_auto_deduction(tree_node*, tree_node*, tree_node*, int,
auto_deduction_context, tree_node*, int)
???:0
0x7da762 tsubst(tree_node*, tree_node*, int, tree_node*)
???:0
0x178bef2 pp_format(pretty_printer*, text_info*)
???:0
0x178c540 pp_format_verbatim(pretty_printer*, text_info*)
???:0
0x178c621 pp_verbatim(pretty_printer*, char const*, ...)
???:0
0x177f6ed diagnostic_report_diagnostic(diagnostic_context*, diagnostic_info*)
???:0
0x17819df warning_at(rich_location*, int, char const*, ...)
???:0
0x6f969d finish_function(bool)
???:0
0x7dcec3 instantiate_decl(tree_node*, bool, bool)
???:0
0x7f7aab instantiate_pending_templates(int)
???:0
0x708f4d c_parse_final_cleanups()
???:0
Please submit a full bug report,
with preprocessed source if appropriate.
Please include the complete backtrace with any bug report.
See <https://gcc.gnu.org/bugs/> for instructions.
My GCC 10.2.0 correctly reports an error like this:
a.cpp:10:23: error: class template argument deduction failed:
10 | q_literal_type<Resolve> operator""_q() {
| ^
a.cpp:10:23: error: no matching function for call to
'LiteralResolver(LiteralResolver<...auto...>)'
a.cpp:3:12: note: candidate: 'template<int N> LiteralResolver(const char
(&)[N])-> LiteralResolver<N>'
3 | constexpr LiteralResolver(const char (&text)[N]) {
| ^~~~~~~~~~~~~~~
a.cpp:3:12: note: template argument deduction/substitution failed:
a.cpp:10:23: note: mismatched types 'const char [N]' and
'LiteralResolver<...auto...>'
10 | q_literal_type<Resolve> operator""_q() {
| ^
a.cpp:2:8: note: candidate: 'template<int N>
LiteralResolver(LiteralResolver<N>)-> LiteralResolver<N>'
2 | struct LiteralResolver {
| ^~~~~~~~~~~~~~~
a.cpp:2:8: note: template argument deduction/substitution failed:
a.cpp:10:23: note: mismatched types 'LiteralResolver<N>' and
'LiteralResolver<...auto...>'
10 | q_literal_type<Resolve> operator""_q() {
| ^
a.cpp: In function 'int operator""_q()':
a.cpp:11:1: warning: no return statement in function returning non-void
[-Wreturn-type]
11 | }
| ^
Looks like a regression. Unfortunately, I don't have the exact build
information for Godbolt's GCC.