]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c++: conversion with trailing return type [PR101051]
authorJason Merrill <jason@redhat.com>
Thu, 7 Apr 2022 01:57:33 +0000 (21:57 -0400)
committerJason Merrill <jason@redhat.com>
Tue, 12 Apr 2022 20:11:44 +0000 (16:11 -0400)
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.

gcc/cp/decl.c
gcc/testsuite/g++.dg/cpp0x/trailing15.C [new file with mode: 0644]

index f71904fcf22b3ffd5a360120c3b9ea0c53c85852..491a03cd94fbdfc3ead09e5b3e28809d01d004b1 100644 (file)
@@ -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 (file)
index 0000000..3fa74d0
--- /dev/null
@@ -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" }