diff options
-rw-r--r-- | include/clang/Basic/DiagnosticSemaKinds.td | 4 | ||||
-rw-r--r-- | lib/AST/Type.cpp | 1 | ||||
-rw-r--r-- | lib/Sema/SemaExpr.cpp | 6 | ||||
-rw-r--r-- | test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.spec.auto/p2.cpp | 4 |
4 files changed, 15 insertions, 0 deletions
diff --git a/include/clang/Basic/DiagnosticSemaKinds.td b/include/clang/Basic/DiagnosticSemaKinds.td index 62e0eb32aa..aa8b240cc2 100644 --- a/include/clang/Basic/DiagnosticSemaKinds.td +++ b/include/clang/Basic/DiagnosticSemaKinds.td @@ -398,6 +398,10 @@ def err_init_reference_member_uninitialized : Error< def note_uninit_reference_member : Note< "uninitialized reference member is here">; +// C++0x auto +def err_auto_variable_cannot_appear_in_own_initializer : Error< + "variable %0 declared with 'auto' type cannot appear in its own initializer">; + // Objective-C++ def err_objc_decls_may_only_appear_in_global_scope : Error< "Objective-C declarations may only appear in global scope">; diff --git a/lib/AST/Type.cpp b/lib/AST/Type.cpp index d76cd249a7..41536612fe 100644 --- a/lib/AST/Type.cpp +++ b/lib/AST/Type.cpp @@ -964,6 +964,7 @@ const char *BuiltinType::getName(bool CPlusPlus) const { case NullPtr: return "nullptr_t"; case Overload: return "<overloaded function type>"; case Dependent: return "<dependent type>"; + case UndeducedAuto: return "<undeduced auto type>"; } } diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp index 3d22321386..2f84306654 100644 --- a/lib/Sema/SemaExpr.cpp +++ b/lib/Sema/SemaExpr.cpp @@ -627,6 +627,12 @@ Sema::OwningExprResult Sema::BuildDeclRefExpr(NamedDecl *D, QualType Ty, SourceLocation Loc, bool TypeDependent, bool ValueDependent, const CXXScopeSpec *SS) { + if (Context.getCanonicalType(Ty) == Context.UndeducedAutoTy) { + Diag(Loc, + diag::err_auto_variable_cannot_appear_in_own_initializer) + << D->getDeclName(); + return ExprError(); + } if (const VarDecl *VD = dyn_cast<VarDecl>(D)) { if (const CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(CurContext)) { diff --git a/test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.spec.auto/p2.cpp b/test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.spec.auto/p2.cpp new file mode 100644 index 0000000000..8f5058ee2d --- /dev/null +++ b/test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.spec.auto/p2.cpp @@ -0,0 +1,4 @@ +// RUN: clang-cc -fsyntax-only -verify %s -std=c++0x +void f() { + auto a = a; // expected-error{{variable 'a' declared with 'auto' type cannot appear in its own initializer}} +} |