[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
Anders Carlsson
andersca at mac.com
Fri Jun 26 11:41:36 PDT 2009
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.
Added:
cfe/trunk/test/SemaCXX/auto-cxx0x.cpp
cfe/trunk/test/SemaCXX/auto-cxx98.cpp
Modified:
cfe/trunk/include/clang/AST/ASTContext.h
cfe/trunk/include/clang/AST/Type.h
cfe/trunk/include/clang/Parse/DeclSpec.h
cfe/trunk/lib/AST/ASTContext.cpp
cfe/trunk/lib/CodeGen/Mangle.cpp
cfe/trunk/lib/Frontend/PCHWriter.cpp
cfe/trunk/lib/Parse/DeclSpec.cpp
cfe/trunk/lib/Parse/ParseDecl.cpp
cfe/trunk/lib/Sema/SemaType.cpp
Modified: cfe/trunk/include/clang/AST/ASTContext.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/ASTContext.h?rev=74307&r1=74306&r2=74307&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/ASTContext.h (original)
+++ cfe/trunk/include/clang/AST/ASTContext.h Fri Jun 26 13:41:36 2009
@@ -192,6 +192,7 @@
QualType VoidPtrTy, NullPtrTy;
QualType OverloadTy;
QualType DependentTy;
+ QualType UndeducedAutoTy;
ASTContext(const LangOptions& LOpts, SourceManager &SM, TargetInfo &t,
IdentifierTable &idents, SelectorTable &sels,
Modified: cfe/trunk/include/clang/AST/Type.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Type.h?rev=74307&r1=74306&r2=74307&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/Type.h (original)
+++ cfe/trunk/include/clang/AST/Type.h Fri Jun 26 13:41:36 2009
@@ -572,7 +572,10 @@
NullPtr, // This is the type of C++0x 'nullptr'.
Overload, // This represents the type of an overloaded function declaration.
- Dependent // This represents the type of a type-dependent expression.
+ Dependent, // This represents the type of a type-dependent expression.
+
+ UndeducedAuto // In C++0x, this represents the type of an auto variable
+ // that has not been deduced yet.
};
private:
Kind TypeKind;
Modified: cfe/trunk/include/clang/Parse/DeclSpec.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Parse/DeclSpec.h?rev=74307&r1=74306&r2=74307&view=diff
==============================================================================
--- cfe/trunk/include/clang/Parse/DeclSpec.h (original)
+++ cfe/trunk/include/clang/Parse/DeclSpec.h Fri Jun 26 13:41:36 2009
@@ -83,6 +83,7 @@
TST_typeofType,
TST_typeofExpr,
TST_decltype, // C++0x decltype
+ TST_auto, // C++0x auto
TST_error // erroneous type
};
Modified: cfe/trunk/lib/AST/ASTContext.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTContext.cpp?rev=74307&r1=74306&r2=74307&view=diff
==============================================================================
--- cfe/trunk/lib/AST/ASTContext.cpp (original)
+++ cfe/trunk/lib/AST/ASTContext.cpp Fri Jun 26 13:41:36 2009
@@ -179,6 +179,10 @@
// expressions.
InitBuiltinType(DependentTy, BuiltinType::Dependent);
+ // Placeholder type for C++0x auto declarations whose real type has
+ // not yet been deduced.
+ InitBuiltinType(UndeducedAutoTy, BuiltinType::UndeducedAuto);
+
// C99 6.2.5p11.
FloatComplexTy = getComplexType(FloatTy);
DoubleComplexTy = getComplexType(DoubleTy);
Modified: cfe/trunk/lib/CodeGen/Mangle.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/Mangle.cpp?rev=74307&r1=74306&r2=74307&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/Mangle.cpp (original)
+++ cfe/trunk/lib/CodeGen/Mangle.cpp Fri Jun 26 13:41:36 2009
@@ -539,6 +539,9 @@
assert(false &&
"Overloaded and dependent types shouldn't get to name mangling");
break;
+ case BuiltinType::UndeducedAuto:
+ assert(0 && "Should not see undeduced auto here");
+ break;
}
}
Modified: cfe/trunk/lib/Frontend/PCHWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/PCHWriter.cpp?rev=74307&r1=74306&r2=74307&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/PCHWriter.cpp (original)
+++ cfe/trunk/lib/Frontend/PCHWriter.cpp Fri Jun 26 13:41:36 2009
@@ -1909,6 +1909,9 @@
case BuiltinType::NullPtr: ID = pch::PREDEF_TYPE_NULLPTR_ID; break;
case BuiltinType::Overload: ID = pch::PREDEF_TYPE_OVERLOAD_ID; break;
case BuiltinType::Dependent: ID = pch::PREDEF_TYPE_DEPENDENT_ID; break;
+ case BuiltinType::UndeducedAuto:
+ assert(0 && "Should not see undeduced auto here");
+ break;
}
Record.push_back((ID << 3) | T.getCVRQualifiers());
Modified: cfe/trunk/lib/Parse/DeclSpec.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/DeclSpec.cpp?rev=74307&r1=74306&r2=74307&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/DeclSpec.cpp (original)
+++ cfe/trunk/lib/Parse/DeclSpec.cpp Fri Jun 26 13:41:36 2009
@@ -173,6 +173,7 @@
case DeclSpec::TST_typename: return "type-name";
case DeclSpec::TST_typeofType:
case DeclSpec::TST_typeofExpr: return "typeof";
+ case DeclSpec::TST_auto: return "auto";
}
}
Modified: cfe/trunk/lib/Parse/ParseDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseDecl.cpp?rev=74307&r1=74306&r2=74307&view=diff
==============================================================================
--- 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);
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}}
+}
Added: cfe/trunk/test/SemaCXX/auto-cxx98.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/auto-cxx98.cpp?rev=74307&view=auto
==============================================================================
--- cfe/trunk/test/SemaCXX/auto-cxx98.cpp (added)
+++ cfe/trunk/test/SemaCXX/auto-cxx98.cpp Fri Jun 26 13:41:36 2009
@@ -0,0 +1,5 @@
+// RUN: clang-cc -fsyntax-only -verify %s -std=c++98
+void f() {
+ auto int a;
+ int auto b;
+}
More information about the cfe-commits
mailing list