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.
return rhs;
}
+ rhs = resolve_nondeduced_context (rhs, complain);
+
if (type_unknown_p (rhs))
{
if (complain & tf_error)
"no context to resolve type of %qE", rhs);
return error_mark_node;
}
-
+
tree ret = build2 (COMPOUND_EXPR, TREE_TYPE (rhs), lhs, rhs);
if (eptype)
ret = build1 (EXCESS_PRECISION_EXPR, eptype, ret);
};
template <typename d, typename c> auto f(d &&, c &&) -> decltype(declval<c>);
struct e {};
-static_assert((e{}, declval<a<int>>),""); // { dg-error "no context to resolve type" }
+static_assert((e{}, declval<a<int>>),"");
--- /dev/null
+// PR c++/115430
+// { dg-do compile }
+
+template<typename T>
+int Func(T);
+typedef int (*funcptrtype)(int);
+funcptrtype fp0 = &Func<int>;
+funcptrtype fp1 = +&Func<int>;
+funcptrtype fp2 = (0, &Func<int>);
+funcptrtype fp3 = (0, +&Func<int>);
+funcptrtype fp4 = (0, 1, &Func<int>);
+
+template<typename T>
+void
+g ()
+{
+ funcptrtype fp5 = (0, &Func<T>);
+}
+
+void
+f ()
+{
+ g<int>();
+}