Implement enough of the 'auto' keyword so we can claim to support N2546.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@74307 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/include/clang/AST/ASTContext.h b/include/clang/AST/ASTContext.h
index 2d35b4d..aa01b7f 100644
--- a/include/clang/AST/ASTContext.h
+++ b/include/clang/AST/ASTContext.h
@@ -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,
diff --git a/include/clang/AST/Type.h b/include/clang/AST/Type.h
index 225a423..321b1f2 100644
--- a/include/clang/AST/Type.h
+++ b/include/clang/AST/Type.h
@@ -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;
diff --git a/include/clang/Parse/DeclSpec.h b/include/clang/Parse/DeclSpec.h
index 10c5ee3..300602e 100644
--- a/include/clang/Parse/DeclSpec.h
+++ b/include/clang/Parse/DeclSpec.h
@@ -83,6 +83,7 @@
TST_typeofType,
TST_typeofExpr,
TST_decltype, // C++0x decltype
+ TST_auto, // C++0x auto
TST_error // erroneous type
};
diff --git a/lib/AST/ASTContext.cpp b/lib/AST/ASTContext.cpp
index 16a62fd..12f75ae 100644
--- a/lib/AST/ASTContext.cpp
+++ b/lib/AST/ASTContext.cpp
@@ -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);
diff --git a/lib/CodeGen/Mangle.cpp b/lib/CodeGen/Mangle.cpp
index 24e441a..b5ad5ac 100644
--- a/lib/CodeGen/Mangle.cpp
+++ b/lib/CodeGen/Mangle.cpp
@@ -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;
}
}
diff --git a/lib/Frontend/PCHWriter.cpp b/lib/Frontend/PCHWriter.cpp
index 808df70..e93219e 100644
--- a/lib/Frontend/PCHWriter.cpp
+++ b/lib/Frontend/PCHWriter.cpp
@@ -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());
diff --git a/lib/Parse/DeclSpec.cpp b/lib/Parse/DeclSpec.cpp
index d8c6986..8b3b285 100644
--- a/lib/Parse/DeclSpec.cpp
+++ b/lib/Parse/DeclSpec.cpp
@@ -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";
}
}
diff --git a/lib/Parse/ParseDecl.cpp b/lib/Parse/ParseDecl.cpp
index c11383c..b2b2f31 100644
--- a/lib/Parse/ParseDecl.cpp
+++ b/lib/Parse/ParseDecl.cpp
@@ -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);
diff --git a/lib/Sema/SemaType.cpp b/lib/Sema/SemaType.cpp
index 8a0ad08..b584142 100644
--- a/lib/Sema/SemaType.cpp
+++ b/lib/Sema/SemaType.cpp
@@ -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;
diff --git a/test/SemaCXX/auto-cxx0x.cpp b/test/SemaCXX/auto-cxx0x.cpp
new file mode 100644
index 0000000..33156ef
--- /dev/null
+++ b/test/SemaCXX/auto-cxx0x.cpp
@@ -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}}
+}
diff --git a/test/SemaCXX/auto-cxx98.cpp b/test/SemaCXX/auto-cxx98.cpp
new file mode 100644
index 0000000..14670cd
--- /dev/null
+++ b/test/SemaCXX/auto-cxx98.cpp
@@ -0,0 +1,5 @@
+// RUN: clang-cc -fsyntax-only -verify %s -std=c++98
+void f() {
+ auto int a;
+ int auto b;
+}