diff options
author | Ryan Flynn <pizza@parseerror.com> | 2009-07-25 22:29:44 +0000 |
---|---|---|
committer | Ryan Flynn <pizza@parseerror.com> | 2009-07-25 22:29:44 +0000 |
commit | e5dc8594ea999ca576272fa44a0e5ff3754f3cb0 (patch) | |
tree | 8394d33f06820ec0c7f1442aa280ac56113158bf /clang/lib/Sema/SemaDecl.cpp | |
parent | 39c348d91569544c5f1af42d38df30f208cc4884 (diff) | |
download | bcm5719-llvm-e5dc8594ea999ca576272fa44a0e5ff3754f3cb0.tar.gz bcm5719-llvm-e5dc8594ea999ca576272fa44a0e5ff3754f3cb0.zip |
PR3575 - warn on declared variable or function attributes after a definition, which are currently ignored.
llvm-svn: 77095
Diffstat (limited to 'clang/lib/Sema/SemaDecl.cpp')
-rw-r--r-- | clang/lib/Sema/SemaDecl.cpp | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp index 07e1ce77de8..0f4e9a42d6e 100644 --- a/clang/lib/Sema/SemaDecl.cpp +++ b/clang/lib/Sema/SemaDecl.cpp @@ -2085,6 +2085,15 @@ Sema::ActOnVariableDeclarator(Scope* S, Declarator& D, DeclContext* DC, CheckVariableDeclaration(NewVD, PrevDecl, Redeclaration); + // attributes declared post-definition are currently ignored + if (PrevDecl) { + const VarDecl *Def = 0, *PrevVD = dyn_cast<VarDecl>(PrevDecl); + if (PrevVD->getDefinition(Def) && D.hasAttributes()) { + Diag(NewVD->getLocation(), diag::warn_attribute_precede_definition); + Diag(Def->getLocation(), diag::note_previous_definition); + } + } + // If this is a locally-scoped extern C variable, update the map of // such variables. if (CurContext->isFunctionOrMethod() && NewVD->isExternC(Context) && @@ -2582,6 +2591,16 @@ Sema::ActOnFunctionDeclarator(Scope* S, Declarator& D, DeclContext* DC, // FIXME: This needs to happen before we merge declarations. Then, // let attribute merging cope with attribute conflicts. ProcessDeclAttributes(S, NewFD, D); + + // attributes declared post-definition are currently ignored + if (PrevDecl) { + const FunctionDecl *Def, *PrevFD = dyn_cast<FunctionDecl>(PrevDecl); + if (PrevFD && PrevFD->getBody(Def) && D.hasAttributes()) { + Diag(NewFD->getLocation(), diag::warn_attribute_precede_definition); + Diag(Def->getLocation(), diag::note_previous_definition); + } + } + AddKnownFunctionAttributes(NewFD); if (OverloadableAttrRequired && !NewFD->getAttr<OverloadableAttr>()) { |