Reject trailing return type for an operator auto().
authorVille Voutilainen <ville.voutilainen@gmail.com>
Mon, 20 Apr 2015 20:44:25 +0000 (23:44 +0300)
committerJason Merrill <jason@gcc.gnu.org>
Mon, 20 Apr 2015 20:44:25 +0000 (16:44 -0400)
* decl.c (grokdeclarator): Reject trailing return types for
all conversion operators, don't handle conversion operators
in the previous checks that deal with auto.

From-SVN: r222248

gcc/cp/ChangeLog
gcc/cp/decl.c
gcc/testsuite/g++.dg/cpp0x/auto9.C

index 08d1010b64d4595483ba4c5e56929c520e5e8f82..f7da7c61b0df3925208e07d353350082636099c2 100644 (file)
@@ -1,3 +1,10 @@
+2015-04-20  Ville Voutilainen  <ville.voutilainen@gmail.com>
+
+       Reject trailing return type for an operator auto().
+       * decl.c (grokdeclarator): Reject trailing return types for
+       all conversion operators, don't handle conversion operators
+       in the previous checks that deal with auto.
+
 2015-04-20  Ilya Verbin  <ilya.verbin@intel.com>
 
        * parser.c (cp_parser_omp_target_update): Add missed %> to error_at ().
index b920fe7da0b69f58f3e988b94f07acd7524bc9a5..29d6e73ca31ff5ef9a6630c7a4c39e9e6ad4ea71 100644 (file)
@@ -9782,7 +9782,7 @@ grokdeclarator (const cp_declarator *declarator,
                            virtualp = false;
                          }
                      }
-                   else if (!is_auto (type))
+                   else if (!is_auto (type) && sfk != sfk_conversion)
                      {
                        error ("%qs function with trailing return type has"
                               " %qT as its type rather than plain %<auto%>",
@@ -9790,7 +9790,8 @@ grokdeclarator (const cp_declarator *declarator,
                        return error_mark_node;
                      }
                  }
-               else if (declarator->u.function.late_return_type)
+               else if (declarator->u.function.late_return_type
+                        && sfk != sfk_conversion)
                  {
                    if (cxx_dialect < cxx11)
                      /* Not using maybe_warn_cpp0x because this should
@@ -9899,6 +9900,8 @@ 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");
              }
 
            arg_types = grokparms (declarator->u.function.parameters,
index 0c0f39f02c65c6f350e0e5a56a60a1f1aa89ee3e..83efbaa534e812f172501fb8fefb68ec0ab404a6 100644 (file)
@@ -21,8 +21,8 @@ struct A
 
 struct A2
 {
-  operator auto () -> int;                     // { dg-error "invalid use of" "" { target { ! c++14 } } }
-  operator auto *() -> int;                    // { dg-error "auto" }
+  operator auto () -> int;                     // { dg-error "invalid use of|trailing return type" }
+  operator auto*() -> int;                     // { dg-error "invalid use of|trailing return type" }
 };
 
 template <typename> struct B