summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--clang/include/clang/Basic/DiagnosticSemaKinds.td5
-rw-r--r--clang/lib/Sema/SemaType.cpp6
-rw-r--r--clang/test/SemaCXX/trailing-return-0x.cpp4
3 files changed, 11 insertions, 4 deletions
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 2569fa1cd40..e7f4fdbfbbf 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/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/clang/lib/Sema/SemaType.cpp b/clang/lib/Sema/SemaType.cpp
index edf119486d9..a75327c9d17 100644
--- a/clang/lib/Sema/SemaType.cpp
+++ b/clang/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/clang/test/SemaCXX/trailing-return-0x.cpp b/clang/test/SemaCXX/trailing-return-0x.cpp
index f7e3433a760..cf5e659660e 100644
--- a/clang/test/SemaCXX/trailing-return-0x.cpp
+++ b/clang/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'}}
OpenPOWER on IntegriCloud