]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c++: unresolved overload with comma op [PR115430]
authorMarek Polacek <polacek@redhat.com>
Tue, 25 Jun 2024 21:42:01 +0000 (17:42 -0400)
committerMarek Polacek <polacek@redhat.com>
Mon, 1 Jul 2024 19:08:38 +0000 (15:08 -0400)
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.

gcc/cp/typeck.cc
gcc/testsuite/g++.dg/cpp0x/noexcept41.C
gcc/testsuite/g++.dg/overload/addr3.C [new file with mode: 0644]

index 50f48768a95d59cf54a543fc83fb22fea4d37d99..55ee867d3292254de848b10d0d45891173a374f7 100644 (file)
@@ -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);
index 4cd3d8d78544a85961720076946db70cd41262dc..7c65cebb618bdfe2a6de912e31bb12c2da7cf116 100644 (file)
@@ -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 (file)
index 0000000..b203326
--- /dev/null
@@ -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>();
+}