diff options
| author | Anders Carlsson <andersca@mac.com> | 2009-12-12 00:32:00 +0000 |
|---|---|---|
| committer | Anders Carlsson <andersca@mac.com> | 2009-12-12 00:32:00 +0000 |
| commit | e363c8e1dfe67f20d768aca2397dae248b9839e6 (patch) | |
| tree | e3f257e9eb0bacdcc70f64cf8b411ec1818c6405 /clang/lib | |
| parent | 22f443f58c0b37fea8727d8d7968df31dfa0a1b8 (diff) | |
| download | bcm5719-llvm-e363c8e1dfe67f20d768aca2397dae248b9839e6.tar.gz bcm5719-llvm-e363c8e1dfe67f20d768aca2397dae248b9839e6.zip | |
Correctly diagnose [basic.stc.dynamic.allocation]p1
llvm-svn: 91190
Diffstat (limited to 'clang/lib')
| -rw-r--r-- | clang/lib/Sema/SemaDeclCXX.cpp | 40 |
1 files changed, 29 insertions, 11 deletions
diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp index b00b1886f14..08fe28998d9 100644 --- a/clang/lib/Sema/SemaDeclCXX.cpp +++ b/clang/lib/Sema/SemaDeclCXX.cpp @@ -4604,8 +4604,35 @@ Sema::CheckReferenceInit(Expr *&Init, QualType DeclType, } } +static inline bool +CheckOperatorNewDeleteDeclarationScope(Sema &SemaRef, + const FunctionDecl *FnDecl) { + const DeclContext *DC = FnDecl->getDeclContext()->getLookupContext(); + if (isa<NamespaceDecl>(DC)) { + return SemaRef.Diag(FnDecl->getLocation(), + diag::err_operator_new_delete_declared_in_namespace) + << FnDecl->getDeclName(); + } + + if (isa<TranslationUnitDecl>(DC) && + FnDecl->getStorageClass() == FunctionDecl::Static) { + return SemaRef.Diag(FnDecl->getLocation(), + diag::err_operator_new_delete_declared_static) + << FnDecl->getDeclName(); + } + + return true; +} + static bool CheckOperatorNewDeclaration(Sema &SemaRef, FunctionDecl *FnDecl) { + // C++ [basic.stc.dynamic.allocation]p1: + // A program is ill-formed if an allocation function is declared in a + // namespace scope other than global scope or declared static in global + // scope. + if (CheckOperatorNewDeleteDeclarationScope(SemaRef, FnDecl)) + return true; + bool ret = false; if (FunctionDecl::param_iterator Param = FnDecl->param_begin()) { QualType SizeTy = @@ -4632,17 +4659,8 @@ CheckOperatorDeleteDeclaration(Sema &SemaRef, const FunctionDecl *FnDecl) { // A program is ill-formed if deallocation functions are declared in a // namespace scope other than global scope or declared static in global // scope. - const DeclContext *DC = FnDecl->getDeclContext()->getLookupContext(); - if (isa<NamespaceDecl>(DC)) { - return SemaRef.Diag(FnDecl->getLocation(), - diag::err_operator_new_delete_declared_in_namespace) - << FnDecl->getDeclName(); - } else if (isa<TranslationUnitDecl>(DC) && - FnDecl->getStorageClass() == FunctionDecl::Static) { - return SemaRef.Diag(FnDecl->getLocation(), - diag::err_operator_new_delete_declared_static) - << FnDecl->getDeclName(); - } + if (CheckOperatorNewDeleteDeclarationScope(SemaRef, FnDecl)) + return true; // C++ [basic.stc.dynamic.deallocation]p2: // Each deallocation function shall return void and its first parameter |

