Bug 89876 - [8 Regression] ICE in convert_like_real on decltype expression involving string conversion to char*
Summary: [8 Regression] ICE in convert_like_real on decltype expression involving stri...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 9.0
: P3 normal
Target Milestone: 8.4
Assignee: Marek Polacek
URL:
Keywords: ice-on-invalid-code
Depends on:
Blocks:
 
Reported: 2019-03-28 21:39 UTC by Martin Sebor
Modified: 2019-05-07 16:32 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail: 8.3.0, 9.0
Last reconfirmed: 2019-03-29 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Martin Sebor 2019-03-28 21:39:38 UTC
The following ill-formed test case triggers an ICE in GCC 8 and 9:

$ cat u.C && gcc -S -Wall -Wextra u.C
template <typename T>
T f (T, char*);

template <typename T>
decltype (f (T (), "")) g (T) { }

void h () { g (0); }

u.C: In substitution of ‘template<class T> decltype (f(T(), "")) g(T) [with T = int]’:
u.C:7:17:   required from here
u.C:5:20: warning: ISO C++ forbids converting a string constant to ‘char*’ [-Wwrite-strings]
    5 | decltype (f (T (), "")) g (T) { }
      |                    ^~
‘
Internal compiler error: Error reporting routines re-entered.
0xb7e259 string_conv_p(tree_node const*, tree_node const*, int)
	/src/gcc/git-svn/gcc/cp/typeck.c:2243
0x8435b5 convert_like_real
	/src/gcc/git-svn/gcc/cp/call.c:7449
0x8470b6 build_over_call
	/src/gcc/git-svn/gcc/cp/call.c:8379
0x837221 build_new_function_call(tree_node*, vec<tree_node*, va_gc, vl_embed>**, int)
	/src/gcc/git-svn/gcc/cp/call.c:4519
0xb20ec0 finish_call_expr(tree_node*, vec<tree_node*, va_gc, vl_embed>**, bool, bool, int)
	/src/gcc/git-svn/gcc/cp/semantics.c:2585
0xaca585 tsubst_copy_and_build(tree_node*, tree_node*, int, tree_node*, bool, bool)
	/src/gcc/git-svn/gcc/cp/pt.c:19022
0xab38ae tsubst(tree_node*, tree_node*, int, tree_node*)
	/src/gcc/git-svn/gcc/cp/pt.c:15068
0x960b6c dump_template_bindings
	/src/gcc/git-svn/gcc/cp/error.c:407
0x96747e dump_substitution
	/src/gcc/git-svn/gcc/cp/error.c:1544
0x968a99 dump_function_decl
	/src/gcc/git-svn/gcc/cp/error.c:1700
0x96617a dump_decl
	/src/gcc/git-svn/gcc/cp/error.c:1278
0x96f216 decl_to_string
	/src/gcc/git-svn/gcc/cp/error.c:3076
0x97239b cp_printer
	/src/gcc/git-svn/gcc/cp/error.c:4090
0x23f7fef pp_format(pretty_printer*, text_info*)
	/src/gcc/git-svn/gcc/pretty-print.c:1390
0x23f83f9 pp_format_verbatim(pretty_printer*, text_info*)
	/src/gcc/git-svn/gcc/pretty-print.c:1452
0x23f8ac7 pp_verbatim(pretty_printer*, char const*, ...)
	/src/gcc/git-svn/gcc/pretty-print.c:1671
0x970c67 print_instantiation_full_context
	/src/gcc/git-svn/gcc/cp/error.c:3474
0x9711c0 maybe_print_instantiation_context
	/src/gcc/git-svn/gcc/cp/error.c:3622
0x96fbda cp_diagnostic_starter
	/src/gcc/git-svn/gcc/cp/error.c:3325
0x23d6c5b diagnostic_report_diagnostic(diagnostic_context*, diagnostic_info*)
	/src/gcc/git-svn/gcc/diagnostic.c:1016
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.
Comment 1 Martin Sebor 2019-03-28 21:43:00 UTC
Bisection points to r254437:

r254437 | marxin | 2017-11-06 04:02:15 -0500 (Mon, 06 Nov 2017) | 25 lines

Instrument function exit with __builtin_unreachable in C++


Prior to that change GCC would reject the test case with a slightly better for of an ICE:

t.C: In substitution of ‘template<class T> decltype (f(T(), "")) g(T) [with T = int]’:
t.C:7:17:   required from here
t.C:5:13: warning: ISO C++ forbids converting a string constant to ‘char*’ [-Wwrite-strings]
 decltype (f (T (), "")) g (T) { }
           ~~^~~~~~~~~~
t.C: In instantiation of ‘decltype (f(T(), "")) g(T) [with T = int]’:
t.C:5:25: sorry, unimplemented: string literal in function template signature
 decltype (f (T (), "")) g (T) { }
                         ^
Comment 2 Martin Sebor 2019-03-28 21:47:03 UTC
I stumbled into it while working on a fix for bug 47488 for GCC 9, which in turn was precipitated by bug 89833.
Comment 3 Marek Polacek 2019-03-29 13:24:39 UTC
I have a fix for the ICE.
Comment 4 Marek Polacek 2019-03-29 18:41:02 UTC
Author: mpolacek
Date: Fri Mar 29 18:40:31 2019
New Revision: 270021

URL: https://gcc.gnu.org/viewcvs?rev=270021&root=gcc&view=rev
Log:
	PR c++/89876 - ICE with deprecated conversion.
	* call.c (convert_like_real): Only give warnings with tf_warning.

	* g++.dg/warn/conv5.C: New test.

Added:
    trunk/gcc/testsuite/g++.dg/warn/conv5.C
Modified:
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/call.c
    trunk/gcc/testsuite/ChangeLog
Comment 5 Marek Polacek 2019-03-29 18:42:27 UTC
Fixed on trunk so far.
Comment 6 Marek Polacek 2019-05-07 16:30:14 UTC
Author: mpolacek
Date: Tue May  7 16:29:39 2019
New Revision: 270974

URL: https://gcc.gnu.org/viewcvs?rev=270974&root=gcc&view=rev
Log:
	PR c++/89876 - ICE with deprecated conversion.
	* call.c (convert_like_real): Only give warnings with tf_warning.

Added:
    branches/gcc-8-branch/gcc/testsuite/g++.dg/warn/conv5.C
Modified:
    branches/gcc-8-branch/gcc/cp/ChangeLog
    branches/gcc-8-branch/gcc/cp/call.c
Comment 7 Marek Polacek 2019-05-07 16:32:36 UTC
Fixed.