diff options
author | Anders Carlsson <andersca@mac.com> | 2009-06-24 00:28:53 +0000 |
---|---|---|
committer | Anders Carlsson <andersca@mac.com> | 2009-06-24 00:28:53 +0000 |
commit | e98da2e7af16056a53db327b520d4b53b4be5e7a (patch) | |
tree | ca235340c55c03cafbd70bd33347241cf1e97848 | |
parent | c5c903acd805581dc7ef881f7cb8df38afca4468 (diff) |
Support for [class.local]p4.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@74030 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | include/clang/Basic/DiagnosticSemaKinds.td | 2 | ||||
-rw-r--r-- | lib/Sema/SemaDecl.cpp | 9 | ||||
-rw-r--r-- | lib/Sema/SemaStmt.cpp | 1 | ||||
-rw-r--r-- | test/CXX/class/class.local/p4.cpp | 10 |
4 files changed, 21 insertions, 1 deletions
diff --git a/include/clang/Basic/DiagnosticSemaKinds.td b/include/clang/Basic/DiagnosticSemaKinds.td index 5b96f81677..d9b268eb94 100644 --- a/include/clang/Basic/DiagnosticSemaKinds.td +++ b/include/clang/Basic/DiagnosticSemaKinds.td @@ -1608,6 +1608,8 @@ def err_reference_to_local_var_in_enclosing_function : Error< "reference to local variable %0 declared in enclosed function %1">; def note_local_variable_declared_here : Note< "%0 declared here">; +def err_static_data_member_not_allowed_in_local_class : Error< + "static data member %0 not allowed in local class %1">; // C++ derived classes def err_base_clause_on_union : Error<"unions cannot have base classes">; diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp index 48d1d64de1..7c4cb60fd5 100644 --- a/lib/Sema/SemaDecl.cpp +++ b/lib/Sema/SemaDecl.cpp @@ -1807,6 +1807,15 @@ Sema::ActOnVariableDeclarator(Scope* S, Declarator& D, DeclContext* DC, } else if (SC == VarDecl::None) SC = VarDecl::Static; } + if (SC == VarDecl::Static) { + if (const CXXRecordDecl *RD = dyn_cast<CXXRecordDecl>(DC)) { + if (RD->isLocalClass()) + Diag(D.getIdentifierLoc(), + diag::err_static_data_member_not_allowed_in_local_class) + << Name << RD->getDeclName(); + } + } + // The variable can not NewVD = VarDecl::Create(Context, DC, D.getIdentifierLoc(), diff --git a/lib/Sema/SemaStmt.cpp b/lib/Sema/SemaStmt.cpp index 5a91496db1..914839cbf7 100644 --- a/lib/Sema/SemaStmt.cpp +++ b/lib/Sema/SemaStmt.cpp @@ -835,7 +835,6 @@ static bool IsReturnCopyElidable(ASTContext &Ctx, QualType RetType, Action::OwningStmtResult Sema::ActOnReturnStmt(SourceLocation ReturnLoc, FullExprArg rex) { - bool RetValExprIsValid = !rex->isInvalid(); Expr *RetValExp = rex->takeAs<Expr>(); if (CurBlock) return ActOnBlockReturnStmt(ReturnLoc, RetValExp); diff --git a/test/CXX/class/class.local/p4.cpp b/test/CXX/class/class.local/p4.cpp new file mode 100644 index 0000000000..40702ad968 --- /dev/null +++ b/test/CXX/class/class.local/p4.cpp @@ -0,0 +1,10 @@ +// RUN: clang-cc -fsyntax-only -verify %s + +void f() { + struct X { + static int a; // expected-error {{static data member 'a' not allowed in local class 'X'}} + int b; + + static void f() { } + }; +}
\ No newline at end of file |