public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r11-9823] c++: conversion with trailing return type [PR101051]
@ 2022-04-12 20:14 Jason Merrill
  0 siblings, 0 replies; only message in thread
From: Jason Merrill @ 2022-04-12 20:14 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:25167a3d8cfc738deb4b2bfb74ad37fd8a0f1ca4

commit r11-9823-g25167a3d8cfc738deb4b2bfb74ad37fd8a0f1ca4
Author: Jason Merrill <jason@redhat.com>
Date:   Wed Apr 6 21:57:33 2022 -0400

    c++: conversion with trailing return type [PR101051]
    
    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.
    
            PR c++/101051
    
    gcc/cp/ChangeLog:
    
            * decl.c (grokdeclarator): Reject conversion with trailing return
            sooner.
    
    gcc/testsuite/ChangeLog:
    
            * g++.dg/cpp0x/trailing15.C: New test.

Diff:
---
 gcc/cp/decl.c                           |  7 +++++--
 gcc/testsuite/g++.dg/cpp0x/trailing15.C | 14 ++++++++++++++
 2 files changed, 19 insertions(+), 2 deletions(-)

diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c
index f71904fcf22..491a03cd94f 100644
--- a/gcc/cp/decl.c
+++ b/gcc/cp/decl.c
@@ -12594,6 +12594,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;
@@ -12758,8 +12763,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" }


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2022-04-12 20:14 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-12 20:14 [gcc r11-9823] c++: conversion with trailing return type [PR101051] Jason Merrill

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).