Skip to content

Commit 21600f3

Browse files
committed
c++: unresolved overload with comma op [PR115430]
This works: template<typename T> int Func(T); typedef int (*funcptrtype)(int); funcptrtype fp0 = &Func<int>; but this doesn't: funcptrtype fp2 = (0, &Func<int>); because we only call resolve_nondeduced_context on the LHS (via convert_to_void) but not on the RHS, so cp_build_compound_expr's type_unknown_p check issues an error. PR c++/115430 gcc/cp/ChangeLog: * typeck.cc (cp_build_compound_expr): Call resolve_nondeduced_context on RHS. gcc/testsuite/ChangeLog: * g++.dg/cpp0x/noexcept41.C: Remove dg-error. * g++.dg/overload/addr3.C: New test. (cherry picked from commit c847dcf)
1 parent 3fe6135 commit 21600f3

File tree

3 files changed

+28
-2
lines changed

3 files changed

+28
-2
lines changed

gcc/cp/typeck.cc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8169,14 +8169,16 @@ cp_build_compound_expr (tree lhs, tree rhs, tsubst_flags_t complain)
81698169
return rhs;
81708170
}
81718171

8172+
rhs = resolve_nondeduced_context (rhs, complain);
8173+
81728174
if (type_unknown_p (rhs))
81738175
{
81748176
if (complain & tf_error)
81758177
error_at (cp_expr_loc_or_input_loc (rhs),
81768178
"no context to resolve type of %qE", rhs);
81778179
return error_mark_node;
81788180
}
8179-
8181+
81808182
tree ret = build2 (COMPOUND_EXPR, TREE_TYPE (rhs), lhs, rhs);
81818183
if (eptype)
81828184
ret = build1 (EXCESS_PRECISION_EXPR, eptype, ret);

gcc/testsuite/g++.dg/cpp0x/noexcept41.C

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@ template <typename> struct a {
99
};
1010
template <typename d, typename c> auto f(d &&, c &&) -> decltype(declval<c>);
1111
struct e {};
12-
static_assert((e{}, declval<a<int>>),""); // { dg-error "no context to resolve type" }
12+
static_assert((e{}, declval<a<int>>),"");

gcc/testsuite/g++.dg/overload/addr3.C

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// PR c++/115430
2+
// { dg-do compile }
3+
4+
template<typename T>
5+
int Func(T);
6+
typedef int (*funcptrtype)(int);
7+
funcptrtype fp0 = &Func<int>;
8+
funcptrtype fp1 = +&Func<int>;
9+
funcptrtype fp2 = (0, &Func<int>);
10+
funcptrtype fp3 = (0, +&Func<int>);
11+
funcptrtype fp4 = (0, 1, &Func<int>);
12+
13+
template<typename T>
14+
void
15+
g ()
16+
{
17+
funcptrtype fp5 = (0, &Func<T>);
18+
}
19+
20+
void
21+
f ()
22+
{
23+
g<int>();
24+
}

0 commit comments

Comments
 (0)