https://gcc.gnu.org/g:c847dcf94499da62e5a28921b404e6e561645d99

commit r15-1759-gc847dcf94499da62e5a28921b404e6e561645d99
Author: Marek Polacek <pola...@redhat.com>
Date:   Tue Jun 25 17:42:01 2024 -0400

    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.

Diff:
---
 gcc/cp/typeck.cc                        |  4 +++-
 gcc/testsuite/g++.dg/cpp0x/noexcept41.C |  2 +-
 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 50f48768a95..55ee867d329 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 4cd3d8d7854..7c65cebb618 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 00000000000..b203326de32
--- /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>();
+}

Reply via email to