Split out from PR23624. For
template<int> void f() { int *t, i; t[i ? 0 : i]; } the C++ frontend creates i ? 0 : i, i.e. an integer type conditional, instead of i != 0 ? 0 : i in case of a template only. Causing this is build_x_conditional_expr ... expr = build_conditional_expr (ifexp, op1, op2); if (processing_template_decl && expr != error_mark_node) return build_min_non_dep (COND_EXPR, expr, orig_ifexp, orig_op1, orig_op2); where in the case of a template decl, the valid expr i != 0 ? 0 : i is thrown away and rebuilt as i ? 0 : i, where the default conversion is no longer applied. That could be fixed using perform_implicit_conversion (boolean_type_node, orig_ifexp) - but I don't know if that would succeed in case of i being a template param. We use this (potentially dependent) expr later to create a non-dependent expr where we fail to apply the default conversion, too, in pt.c:build_non_dependent_expr we could fix that there, too, performing default conversion if the type is not correct. And later in typeck.c:build_array_ref we happen to call fold on the invalid(?) COND_EXPR. patch: http://gcc.gnu.org/ml/gcc-patches/2005-08/msg01740.html -- Summary: C++ frontend passes invalid COND_EXPR to the middle-end Product: gcc Version: 4.1.0 Status: UNCONFIRMED Severity: normal Priority: P2 Component: c++ AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: rguenth at gcc dot gnu dot org CC: gcc-bugs at gcc dot gnu dot org http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23794