diff mbox series

[pushed] c++: conversion with trailing return type [PR101051]

Message ID 20220407032638.2422771-1-jason@redhat.com
State New
Headers show
Series [pushed] c++: conversion with trailing return type [PR101051] | expand

Commit Message

Jason Merrill April 7, 2022, 3:26 a.m. UTC
We've had a diagnostic for this, but since r10-6571 added an assert to
splice_late_return_type, we need to diagnose before we call it.

Tested x86_64-pc-linux-gnu, applying to trunk.

	PR c++/101051

gcc/cp/ChangeLog:

	* decl.cc (grokdeclarator): Reject conversion with trailing return
	sooner.

gcc/testsuite/ChangeLog:

	* g++.dg/cpp0x/trailing15.C: New test.
---
 gcc/cp/decl.cc                          |  7 +++++--
 gcc/testsuite/g++.dg/cpp0x/trailing15.C | 14 ++++++++++++++
 2 files changed, 19 insertions(+), 2 deletions(-)
 create mode 100644 gcc/testsuite/g++.dg/cpp0x/trailing15.C


base-commit: 8e4339f5023286d25c7dfa40b4c88e63b780cfd7
diff mbox series

Patch

diff --git a/gcc/cp/decl.cc b/gcc/cp/decl.cc
index 0ff13e99595..c136dbbba1a 100644
--- a/gcc/cp/decl.cc
+++ b/gcc/cp/decl.cc
@@ -12866,6 +12866,11 @@  grokdeclarator (const cp_declarator *declarator,
 			    "type specifier", name);
 		return error_mark_node;
 	      }
+	    if (late_return_type && sfk == sfk_conversion)
+	      {
+		error ("a conversion function cannot have a trailing return type");
+		return error_mark_node;
+	      }
 	    type = splice_late_return_type (type, late_return_type);
 	    if (type == error_mark_node)
 	      return error_mark_node;
@@ -13030,8 +13035,6 @@  grokdeclarator (const cp_declarator *declarator,
 		    maybe_warn_cpp0x (CPP0X_EXPLICIT_CONVERSION);
 		    explicitp = 2;
 		  }
-		if (late_return_type_p)
-		  error ("a conversion function cannot have a trailing return type");
 	      }
 	    else if (sfk == sfk_deduction_guide)
 	      {
diff --git a/gcc/testsuite/g++.dg/cpp0x/trailing15.C b/gcc/testsuite/g++.dg/cpp0x/trailing15.C
new file mode 100644
index 00000000000..3fa74d08e39
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/trailing15.C
@@ -0,0 +1,14 @@ 
+// PR c++/101051
+// { dg-do compile { target c++11 } }
+
+template <class T>
+class Foo
+{
+    constexpr operator T() -> T {} // { dg-error "trailing return" }
+};
+
+struct S {
+  operator int() const -> double; // { dg-error "trailing return" }
+};
+
+class A { operator auto*() -> int; }; // { dg-error "auto|trailing return" }