fn[0]() ICEs because we end up with addr_expr of a decl, and that should only happen for artificial or otherwise special internal functions. For anything else, we should find the decl earlier, but we don't because we build an indirect_ref or an addr_expr and don't cancel them out. Let fold do its job when building the array indexing indirect_ref, and the ICE is gone.
Regstrapped on i686- and x86_64-linux-gnu. Ok to install? for gcc/cp/ChangeLog PR c++/84943 * typeck.c (cp_build_array_ref): Allow the indirect_ref to be folded. for gcc/testsuite/ChangeLog PR c++/84943 * g++.dg/pr84943.C: New. --- gcc/cp/typeck.c | 10 +++++----- gcc/testsuite/g++.dg/pr84943.C | 8 ++++++++ 2 files changed, 13 insertions(+), 5 deletions(-) create mode 100644 gcc/testsuite/g++.dg/pr84943.C diff --git a/gcc/cp/typeck.c b/gcc/cp/typeck.c index d3183b5321d3..5d08cb78a388 100644 --- a/gcc/cp/typeck.c +++ b/gcc/cp/typeck.c @@ -3393,11 +3393,11 @@ cp_build_array_ref (location_t loc, tree array, tree idx, warn_array_subscript_with_type_char (loc, idx); - ret = cp_build_indirect_ref (cp_build_binary_op (input_location, - PLUS_EXPR, ar, ind, - complain), - RO_ARRAY_INDEXING, - complain); + ret = cp_build_indirect_ref_1 (cp_build_binary_op (input_location, + PLUS_EXPR, ar, ind, + complain), + RO_ARRAY_INDEXING, + complain, true); protected_set_expr_location (ret, loc); if (non_lvalue) ret = non_lvalue_loc (loc, ret); diff --git a/gcc/testsuite/g++.dg/pr84943.C b/gcc/testsuite/g++.dg/pr84943.C new file mode 100644 index 000000000000..36f75a164119 --- /dev/null +++ b/gcc/testsuite/g++.dg/pr84943.C @@ -0,0 +1,8 @@ +// { dg-do compile } + +// Avoid -pedantic-error default +// { dg-options "" } + +void a() { + a[0](); // { dg-warning "arithmetic" } +} -- Alexandre Oliva, freedom fighter http://FSFLA.org/~lxoliva/ You must be the change you wish to see in the world. -- Gandhi Be Free! -- http://FSFLA.org/ FSF Latin America board member Free Software Evangelist|Red Hat Brasil GNU Toolchain Engineer