[cfe-commits] r74307 - in /cfe/trunk: include/clang/AST/ASTContext.h include/clang/AST/Type.h include/clang/Parse/DeclSpec.h lib/AST/ASTContext.cpp lib/CodeGen/Mangle.cpp lib/Frontend/PCHWriter.cpp lib/Parse/DeclSpec.cpp lib/Parse/ParseDecl.cpp lib/Sema/SemaType.cpp test/SemaCXX/auto-cxx0x.cpp test/SemaCXX/auto-cxx98.cpp
Douglas Gregor
dgregor at apple.com
Fri Jun 26 11:54:26 PDT 2009
On Jun 26, 2009, at 11:41 AM, Anders Carlsson wrote:
> Author: andersca
> Date: Fri Jun 26 13:41:36 2009
> New Revision: 74307
>
> URL: http://llvm.org/viewvc/llvm-project?rev=74307&view=rev
> Log:
> Implement enough of the 'auto' keyword so we can claim to support
> N2546.
>
> =
> =
> =
> =
> =
> =
> =
> =
> ======================================================================
> --- cfe/trunk/lib/Parse/ParseDecl.cpp (original)
> +++ cfe/trunk/lib/Parse/ParseDecl.cpp Fri Jun 26 13:41:36 2009
> @@ -926,7 +926,10 @@
> isInvalid = DS.SetStorageClassSpec(DeclSpec::SCS_static, Loc,
> PrevSpec);
> break;
> case tok::kw_auto:
> - isInvalid = DS.SetStorageClassSpec(DeclSpec::SCS_auto, Loc,
> PrevSpec);
> + if (getLang().CPlusPlus0x)
> + isInvalid = DS.SetTypeSpecType(DeclSpec::TST_auto, Loc,
> PrevSpec);
> + else
> + isInvalid = DS.SetStorageClassSpec(DeclSpec::SCS_auto, Loc,
> PrevSpec);
> break;
> case tok::kw_register:
> isInvalid = DS.SetStorageClassSpec(DeclSpec::SCS_register,
> Loc, PrevSpec);
Such a beautiful place to add a warning for -Wc++0x :)
> Modified: cfe/trunk/lib/Sema/SemaType.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaType.cpp?rev=74307&r1=74306&r2=74307&view=diff
>
> =
> =
> =
> =
> =
> =
> =
> =
> ======================================================================
> --- cfe/trunk/lib/Sema/SemaType.cpp (original)
> +++ cfe/trunk/lib/Sema/SemaType.cpp Fri Jun 26 13:41:36 2009
> @@ -245,6 +245,11 @@
> Result = Context.getDecltypeType(E);
> break;
> }
> + case DeclSpec::TST_auto: {
> + // TypeQuals handled by caller.
> + Result = Context.UndeducedAutoTy;
> + break;
> + }
>
> case DeclSpec::TST_error:
> Result = Context.IntTy;
>
> Added: cfe/trunk/test/SemaCXX/auto-cxx0x.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/auto-cxx0x.cpp?rev=74307&view=auto
>
> =
> =
> =
> =
> =
> =
> =
> =
> ======================================================================
> --- cfe/trunk/test/SemaCXX/auto-cxx0x.cpp (added)
> +++ cfe/trunk/test/SemaCXX/auto-cxx0x.cpp Fri Jun 26 13:41:36 2009
> @@ -0,0 +1,5 @@
> +// RUN: clang-cc -fsyntax-only -verify %s -std=c++0x
> +void f() {
> + auto int a; // expected-error{{cannot combine with previous
> 'auto' declaration specifier}}
> + int auto b; // expected-error{{cannot combine with previous 'int'
> declaration specifier}}
> +}
Hmmm... could we give a more targeted diagnostic for this error? This
is valid C++98 code that's becoming invalid in C++0x, so it would help
to tell the user this explicitly, e.g., "C++0x treats the 'auto'
specifier as a type (not a storage class); remove 'auto' to make your
code portable for both C++98 and C++0x" (with a fix-it hint to remove
"auto", naturally).
- Doug
More information about the cfe-commits
mailing list