diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp index b06b884450a9..c7873fa06820 100644 --- a/clang/lib/Sema/SemaDecl.cpp +++ b/clang/lib/Sema/SemaDecl.cpp @@ -6592,11 +6592,16 @@ Decl *Sema::ActOnParamDeclarator(Scope *S, Declarator &D) { const DeclSpec &DS = D.getDeclSpec(); // Verify C99 6.7.5.3p2: The only SCS allowed is 'register'. + // C++03 [dcl.stc]p2 also permits 'auto'. VarDecl::StorageClass StorageClass = SC_None; VarDecl::StorageClass StorageClassAsWritten = SC_None; if (DS.getStorageClassSpec() == DeclSpec::SCS_register) { StorageClass = SC_Register; StorageClassAsWritten = SC_Register; + } else if (getLangOptions().CPlusPlus && + DS.getStorageClassSpec() == DeclSpec::SCS_auto) { + StorageClass = SC_Auto; + StorageClassAsWritten = SC_Auto; } else if (DS.getStorageClassSpec() != DeclSpec::SCS_unspecified) { Diag(DS.getStorageClassSpecLoc(), diag::err_invalid_storage_class_in_func_decl); diff --git a/clang/test/CXX/dcl.dcl/dcl.spec/dcl.stc/p2.cpp b/clang/test/CXX/dcl.dcl/dcl.spec/dcl.stc/p2.cpp new file mode 100644 index 000000000000..44cc5a7cfaa3 --- /dev/null +++ b/clang/test/CXX/dcl.dcl/dcl.spec/dcl.stc/p2.cpp @@ -0,0 +1,26 @@ +// RUN: %clang_cc1 -fsyntax-only -verify -Wno-c++0x-compat %s + +// The auto or register specifiers can be applied only to names of objects +// declared in a block (6.3) or to function parameters (8.4). + +auto int ao; // expected-error {{illegal storage class on file-scoped variable}} +auto void af(); // expected-error {{illegal storage class on function}} + +register int ro; // expected-error {{illegal storage class on file-scoped variable}} +register void rf(); // expected-error {{illegal storage class on function}} + +struct S { + auto int ao; // expected-error {{storage class specified for a member declaration}} + auto void af(); // expected-error {{storage class specified for a member declaration}} + + register int ro; // expected-error {{storage class specified for a member declaration}} + register void rf(); // expected-error {{storage class specified for a member declaration}} +}; + +void foo(auto int ap, register int rp) { + auto int abo; + auto void abf(); // expected-error {{illegal storage class on function}} + + register int rbo; + register void rbf(); // expected-error {{illegal storage class on function}} +}