diff options
author | Marek Polacek <polacek@redhat.com> | 2024-06-25 17:42:01 -0400 |
---|---|---|
committer | Marek Polacek <polacek@redhat.com> | 2024-07-01 15:08:38 -0400 |
commit | c847dcf94499da62e5a28921b404e6e561645d99 (patch) | |
tree | 0ea36c59f97a61120820c269ecace29499c3e4cb /gcc | |
parent | 52d71b6b1f0f465a6cf064f61b22fc99453ec132 (diff) | |
download | gcc-c847dcf94499da62e5a28921b404e6e561645d99.zip gcc-c847dcf94499da62e5a28921b404e6e561645d99.tar.gz gcc-c847dcf94499da62e5a28921b404e6e561645d99.tar.bz2 |
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.
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/cp/typeck.cc | 4 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/cpp0x/noexcept41.C | 2 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/overload/addr3.C | 24 |
3 files changed, 28 insertions, 2 deletions
diff --git a/gcc/cp/typeck.cc b/gcc/cp/typeck.cc index 50f4876..55ee867 100644 --- a/gcc/cp/typeck.cc +++ b/gcc/cp/typeck.cc @@ -8157,6 +8157,8 @@ cp_build_compound_expr (tree lhs, tree rhs, tsubst_flags_t complain) return rhs; } + rhs = resolve_nondeduced_context (rhs, complain); + if (type_unknown_p (rhs)) { if (complain & tf_error) @@ -8164,7 +8166,7 @@ cp_build_compound_expr (tree lhs, tree rhs, tsubst_flags_t complain) "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); diff --git a/gcc/testsuite/g++.dg/cpp0x/noexcept41.C b/gcc/testsuite/g++.dg/cpp0x/noexcept41.C index 4cd3d8d..7c65ceb 100644 --- a/gcc/testsuite/g++.dg/cpp0x/noexcept41.C +++ b/gcc/testsuite/g++.dg/cpp0x/noexcept41.C @@ -9,4 +9,4 @@ template <typename> struct a { }; 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>>),""); diff --git a/gcc/testsuite/g++.dg/overload/addr3.C b/gcc/testsuite/g++.dg/overload/addr3.C new file mode 100644 index 0000000..b203326 --- /dev/null +++ b/gcc/testsuite/g++.dg/overload/addr3.C @@ -0,0 +1,24 @@ +// 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>(); +} |