Skip to content

Commit c847dcf

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.
1 parent 52d71b6 commit c847dcf

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
@@ -8157,14 +8157,16 @@ cp_build_compound_expr (tree lhs, tree rhs, tsubst_flags_t complain)
81578157
return rhs;
81588158
}
81598159

8160+
rhs = resolve_nondeduced_context (rhs, complain);
8161+
81608162
if (type_unknown_p (rhs))
81618163
{
81628164
if (complain & tf_error)
81638165
error_at (cp_expr_loc_or_input_loc (rhs),
81648166
"no context to resolve type of %qE", rhs);
81658167
return error_mark_node;
81668168
}
8167-
8169+
81688170
tree ret = build2 (COMPOUND_EXPR, TREE_TYPE (rhs), lhs, rhs);
81698171
if (eptype)
81708172
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>>),"");
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)