From 3e589a17b2169ce7eff9c73ab2c25015c4bb7d31 Mon Sep 17 00:00:00 2001 From: Richard Smith Date: Fri, 14 Feb 2014 22:17:32 +0000 Subject: [PATCH] Fix crash-on-invalid if decltype(auto) is used as a deduced return type in 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 | 5 ++++- lib/Sema/SemaType.cpp | 6 ++++-- test/SemaCXX/trailing-return-0x.cpp | 4 +++- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/include/clang/Basic/DiagnosticSemaKinds.td b/include/clang/Basic/DiagnosticSemaKinds.td index 2569fa1cd4..e7f4fdbfbb 100644 --- a/include/clang/Basic/DiagnosticSemaKinds.td +++ b/include/clang/Basic/DiagnosticSemaKinds.td @@ -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< diff --git a/lib/Sema/SemaType.cpp b/lib/Sema/SemaType.cpp index edf119486d..a75327c9d1 100644 --- a/lib/Sema/SemaType.cpp +++ b/lib/Sema/SemaType.cpp @@ -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()) { diff --git a/test/SemaCXX/trailing-return-0x.cpp b/test/SemaCXX/trailing-return-0x.cpp index f7e3433a76..cf5e659660 100644 --- a/test/SemaCXX/trailing-return-0x.cpp +++ b/test/SemaCXX/trailing-return-0x.cpp @@ -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'}} -- 2.40.0