public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Jason Merrill <jason@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org
Subject: [gcc r11-9823] c++: conversion with trailing return type [PR101051]
Date: Tue, 12 Apr 2022 20:14:18 +0000 (GMT)	[thread overview]
Message-ID: <20220412201418.80A8D3858C53@sourceware.org> (raw)

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" }


                 reply	other threads:[~2022-04-12 20:14 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220412201418.80A8D3858C53@sourceware.org \
    --to=jason@gcc.gnu.org \
    --cc=gcc-cvs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).