]> granicus.if.org Git - clang/commitdiff
Fix crash-on-invalid if decltype(auto) is used as a deduced return type in
authorRichard Smith <richard-llvm@metafoo.co.uk>
Fri, 14 Feb 2014 22:17:32 +0000 (22:17 +0000)
committerRichard Smith <richard-llvm@metafoo.co.uk>
Fri, 14 Feb 2014 22:17:32 +0000 (22:17 +0000)
C++11 mode. Continue to disallow return type deduction in C++11 for now.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@201438 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Basic/DiagnosticSemaKinds.td
lib/Sema/SemaType.cpp
test/SemaCXX/trailing-return-0x.cpp

index 2569fa1cd408b5540ae9cffcb906c96d6f731b6b..e7f4fdbfbbfc084238b9ae917cbb7b98f049a6f3 100644 (file)
@@ -1527,7 +1527,10 @@ def err_auto_var_init_multiple_expressions : Error<
 def err_auto_new_ctor_multiple_expressions : Error<
   "new expression for type %0 contains multiple constructor arguments">;
 def err_auto_missing_trailing_return : Error<
-  "'auto' return without trailing return type">;
+  "'auto' return without trailing return type; deduced return types are a "
+  "C++1y extension">;
+def err_deduced_return_type : Error<
+  "deduced return types are a C++1y extension">;
 def err_trailing_return_without_auto : Error<
   "function with trailing return type must specify return type 'auto', not %0">;
 def err_trailing_return_in_parens : Error<
index edf119486d984fecb19b4391f33bea9754f7763c..a75327c9d17b0f7ae5eb9412d3b6cc525edd6967 100644 (file)
@@ -2678,11 +2678,13 @@ static TypeSourceInfo *GetFullTypeForDeclarator(TypeProcessingState &state,
       if (!D.isInvalidType()) {
         // trailing-return-type is only required if we're declaring a function,
         // and not, for instance, a pointer to a function.
-        if (D.getDeclSpec().getTypeSpecType() == DeclSpec::TST_auto &&
+        if (D.getDeclSpec().containsPlaceholderType() &&
             !FTI.hasTrailingReturnType() && chunkIndex == 0 &&
             !S.getLangOpts().CPlusPlus1y) {
           S.Diag(D.getDeclSpec().getTypeSpecTypeLoc(),
-               diag::err_auto_missing_trailing_return);
+                 D.getDeclSpec().getTypeSpecType() == DeclSpec::TST_auto
+                     ? diag::err_auto_missing_trailing_return
+                     : diag::err_deduced_return_type);
           T = Context.IntTy;
           D.setInvalidType(true);
         } else if (FTI.hasTrailingReturnType()) {
index f7e3433a76086a0fe8d7e9889d0d833220d5d492..cf5e659660eb0e313346395f8eb8ac46124c872d 100644 (file)
@@ -17,7 +17,9 @@ auto f() -> int
     return 0;
 }
 
-auto g(); // expected-error{{return without trailing return type}}
+auto g(); // expected-error{{return without trailing return type; deduced return types are a C++1y extension}}
+decltype(auto) g2(); // expected-warning{{extension}} expected-error-re{{{{^}}deduced return types are a C++1y extension}}
+auto badness = g2();
 
 int h() -> int; // expected-error{{trailing return type must specify return type 'auto', not 'int'}}