Bug 78765 - [7 Regression] ICE on invalid C++ code on x86_64-linux-gnu (internal compiler error: in cp_build_addr_expr_1, at cp/typeck.c:5708)
Summary: [7 Regression] ICE on invalid C++ code on x86_64-linux-gnu (internal compiler...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 7.0
: P4 normal
Target Milestone: 7.0
Assignee: Nathan Sidwell
URL:
Keywords: error-recovery
Depends on:
Blocks:
 
Reported: 2016-12-10 20:11 UTC by Chengnian Sun
Modified: 2017-01-05 12:32 UTC (History)
4 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2016-12-10 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Chengnian Sun 2016-12-10 20:11:09 UTC
$ gcc-trunk -v
Using built-in specs.
COLLECT_GCC=gcc-trunk
COLLECT_LTO_WRAPPER=/usr/local/gcc-trunk/libexec/gcc/x86_64-pc-linux-gnu/7.0.0/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: ../gcc-source-trunk/configure --enable-languages=c,c++,lto --prefix=/usr/local/gcc-trunk --disable-bootstrap
Thread model: posix
gcc version 7.0.0 20161210 (experimental) [trunk revision 243516] (GCC) 
$ 
$ gcc-trunk small.C
small.C:6:42: error: ‘v’ was not declared in this scope
   static constexpr ValueType doubleval = v;
                                          ^
small.C: In function ‘int main()’:
small.C:9:52: internal compiler error: in cp_build_addr_expr_1, at cp/typeck.c:5708
 int main() { ValueTypeInfo<ValueTypeEnum::doubleval> }
                                                    ^
0x7eb7d5 cp_build_addr_expr_1
	../../gcc-source-trunk/gcc/cp/typeck.c:5708
0x683162 add_function_candidate
	../../gcc-source-trunk/gcc/cp/call.c:2158
0x6848c7 add_candidates
	../../gcc-source-trunk/gcc/cp/call.c:5491
0x67f9e4 build_user_type_conversion_1
	../../gcc-source-trunk/gcc/cp/call.c:3842
0x680a8a implicit_conversion
	../../gcc-source-trunk/gcc/cp/call.c:1898
0x6890dd build_integral_nontype_arg_conv(tree_node*, tree_node*, int)
	../../gcc-source-trunk/gcc/cp/call.c:4025
0x70afa5 convert_nontype_argument
	../../gcc-source-trunk/gcc/cp/pt.c:6434
0x711eed convert_template_argument
	../../gcc-source-trunk/gcc/cp/pt.c:7363
0x71fa63 coerce_template_parms
	../../gcc-source-trunk/gcc/cp/pt.c:7823
0x72199a lookup_template_class_1
	../../gcc-source-trunk/gcc/cp/pt.c:8396
0x72199a lookup_template_class(tree_node*, tree_node*, tree_node*, tree_node*, int, int)
	../../gcc-source-trunk/gcc/cp/pt.c:8738
0x836bed finish_template_type(tree_node*, tree_node*, int)
	../../gcc-source-trunk/gcc/cp/semantics.c:3146
0x7bea14 cp_parser_template_id
	../../gcc-source-trunk/gcc/cp/parser.c:15464
0x7becba cp_parser_class_name
	../../gcc-source-trunk/gcc/cp/parser.c:21879
0x7af07d cp_parser_qualifying_entity
	../../gcc-source-trunk/gcc/cp/parser.c:6293
0x7af07d cp_parser_nested_name_specifier_opt
	../../gcc-source-trunk/gcc/cp/parser.c:5977
0x7acd20 cp_parser_simple_type_specifier
	../../gcc-source-trunk/gcc/cp/parser.c:16793
0x7aa261 cp_parser_type_specifier
	../../gcc-source-trunk/gcc/cp/parser.c:16464
0x7bf3d3 cp_parser_decl_specifier_seq
	../../gcc-source-trunk/gcc/cp/parser.c:13303
0x7c9770 cp_parser_simple_declaration
	../../gcc-source-trunk/gcc/cp/parser.c:12646
Please submit a full bug report,
with preprocessed source if appropriate.
Please include the complete backtrace with any bug report.
See <http://gcc.gnu.org/bugs.html> for instructions.
$ 
$ cat small.C
class ValueType {
  operator int();
  int m_ID;
};
class ValueTypeEnum {
  static constexpr ValueType doubleval = v;
};
template <int> class ValueTypeInfo;
int main() { ValueTypeInfo<ValueTypeEnum::doubleval> }
$
Comment 1 Jakub Jelinek 2016-12-10 22:28:11 UTC
ICE started with r238182.
Comment 2 Marek Polacek 2016-12-13 12:27:12 UTC
The new code in cp_build_addr_expr_1 says
    CASE_CONVERT:
    case FLOAT_EXPR:
    case FIX_TRUNC_EXPR:
      /* We should have handled this above in the lvalue_kind check.  */
we arrived here with NOP_EXPR, but we hadn't issued an error in this block:
  /* Anything not already handled and not a true memory reference
     is an error.  */
  if (TREE_CODE (argtype) != FUNCTION_TYPE
      && TREE_CODE (argtype) != METHOD_TYPE)
because strict_lvalue is false.  ARG is (const struct ValueType) doubleval.
Comment 3 Nathan Sidwell 2017-01-05 12:31:09 UTC
Author: nathan
Date: Thu Jan  5 12:30:26 2017
New Revision: 244101

URL: https://gcc.gnu.org/viewcvs?rev=244101&root=gcc&view=rev
Log:
	cp/
	PR c++/78765
	* pt.c (convert_nontype_argument): Don't try and see if integral
	or enum expressions are constants prematurely.

	testsuite/
	PR c++/78765
	* g++.dg/cpp0x/pr78765.C: New.

Added:
    trunk/gcc/testsuite/g++.dg/cpp0x/pr78765.C
Modified:
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/pt.c
    trunk/gcc/testsuite/ChangeLog
Comment 4 Nathan Sidwell 2017-01-05 12:32:21 UTC
Fixed r244101