Skip to content

Commit 59e0376

Browse files
author
Patrick Palka
committed
c++: unexpected ADDR_EXPR after overload set pruning [PR107461]
Here the ahead-of-time overload set pruning in finish_call_expr is unintentionally returning a CALL_EXPR whose (pruned) callee is wrapped in an ADDR_EXPR, despite the original callee not being wrapped in an ADDR_EXPR. This ends up causing a bogus declaration mismatch error in the below testcase because the call to min in riscvarchive#1 gets expressed as a CALL_EXPR of ADDR_EXPR of FUNCTION_DECL, whereas the level-lowered call to min in riscvarchive#2 gets expressed instead as a CALL_EXPR of FUNCTION_DECL. This patch fixes this by stripping the spurious ADDR_EXPR appropriately. Thus the first call to min now also gets expressed as a CALL_EXPR of FUNCTION_DECL, matching the behavior before r12-6075-g2decd2cabe5a4f. PR c++/107461 gcc/cp/ChangeLog: * semantics.cc (finish_call_expr): Strip ADDR_EXPR from the selected callee during overload set pruning. gcc/testsuite/ChangeLog: * g++.dg/template/call9.C: New test.
1 parent ed2b519 commit 59e0376

File tree

2 files changed

+36
-5
lines changed

2 files changed

+36
-5
lines changed

gcc/cp/semantics.cc

+10-5
Original file line numberDiff line numberDiff line change
@@ -2957,13 +2957,18 @@ finish_call_expr (tree fn, vec<tree, va_gc> **args, bool disallow_virtual,
29572957
if (TREE_CODE (result) == CALL_EXPR
29582958
&& really_overloaded_fn (orig_fn))
29592959
{
2960-
orig_fn = CALL_EXPR_FN (result);
2961-
if (TREE_CODE (orig_fn) == COMPONENT_REF)
2960+
tree sel_fn = CALL_EXPR_FN (result);
2961+
if (TREE_CODE (sel_fn) == COMPONENT_REF)
29622962
{
29632963
/* The non-dependent result of build_new_method_call. */
2964-
orig_fn = TREE_OPERAND (orig_fn, 1);
2965-
gcc_assert (BASELINK_P (orig_fn));
2966-
}
2964+
sel_fn = TREE_OPERAND (sel_fn, 1);
2965+
gcc_assert (BASELINK_P (sel_fn));
2966+
}
2967+
else if (TREE_CODE (sel_fn) == ADDR_EXPR)
2968+
/* Our original callee wasn't wrapped in an ADDR_EXPR,
2969+
so strip this ADDR_EXPR added by build_over_call. */
2970+
sel_fn = TREE_OPERAND (sel_fn, 0);
2971+
orig_fn = sel_fn;
29672972
}
29682973

29692974
result = build_call_vec (TREE_TYPE (result), orig_fn, orig_args);

gcc/testsuite/g++.dg/template/call9.C

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// PR c++/107461
2+
// { dg-do compile { target c++11 } }
3+
4+
template<class T>
5+
constexpr T min(T t0, T t1) {
6+
return t0 < t1 ? t0 : t1;
7+
}
8+
9+
template<int MAX>
10+
struct Matrix;
11+
12+
template<int MAXOP, int other_MAXOP>
13+
Matrix<min(MAXOP, other_MAXOP)>
14+
operator+(Matrix<MAXOP> const& lhs, Matrix<other_MAXOP> const& rhs); // #1
15+
16+
template<int MAX>
17+
struct Matrix {
18+
template<int MAXOP, int other_MAXOP>
19+
friend Matrix<min(MAXOP, other_MAXOP)>
20+
operator+(Matrix<MAXOP> const& lhs, Matrix<other_MAXOP> const& rhs); // #2
21+
};
22+
23+
int main() {
24+
Matrix<1> a;
25+
a+a;
26+
}

0 commit comments

Comments
 (0)