diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td index fabd21b674f0..979ffb28dae5 100644 --- a/clang/include/clang/Basic/DiagnosticSemaKinds.td +++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td @@ -898,7 +898,8 @@ def err_new_array_of_auto : Error< def err_auto_not_allowed : Error< "'auto' not allowed %select{in function prototype|in struct member" "|in union member|in class member|in exception declaration" - "|in template parameter|in block literal|in template argument|here}0">; + "|in template parameter|in block literal|in template argument" + "|in typedef|here}0">; def err_auto_var_requires_init : Error< "declaration of variable %0 with type %1 requires an initializer">; def err_auto_new_requires_ctor_arg : Error< diff --git a/clang/lib/Sema/SemaType.cpp b/clang/lib/Sema/SemaType.cpp index c88baa540f52..8051b560343e 100644 --- a/clang/lib/Sema/SemaType.cpp +++ b/clang/lib/Sema/SemaType.cpp @@ -1483,7 +1483,7 @@ TypeSourceInfo *Sema::GetTypeForDeclarator(Declarator &D, Scope *S, break; case Declarator::TypeNameContext: if (!AutoAllowedInTypeName) - Error = 8; // Generic + Error = 9; // Generic break; case Declarator::FileContext: case Declarator::BlockContext: @@ -1492,6 +1492,9 @@ TypeSourceInfo *Sema::GetTypeForDeclarator(Declarator &D, Scope *S, break; } + if (D.getDeclSpec().getStorageClassSpec() == DeclSpec::SCS_typedef) + Error = 8; + if (Error != -1) { Diag(D.getDeclSpec().getTypeSpecTypeLoc(), diag::err_auto_not_allowed) << Error; diff --git a/clang/test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.spec.auto/p5.cpp b/clang/test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.spec.auto/p5.cpp index 836ccda6f9d7..3724243ede0c 100644 --- a/clang/test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.spec.auto/p5.cpp +++ b/clang/test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.spec.auto/p5.cpp @@ -14,6 +14,9 @@ struct S { operator auto(); // expected-error{{'auto' not allowed here}} }; +typedef auto *AutoPtr; // expected-error{{'auto' not allowed in typedef}} +typedef auto Fun(int a) -> decltype(a + a); + void g(auto a) { // expected-error{{'auto' not allowed in function prototype}} try { } catch (auto &a) { } // expected-error{{'auto' not allowed in exception declaration}}