diff options
author | Kaelyn Uhrain <rikka@google.com> | 2012-11-12 23:48:05 +0000 |
---|---|---|
committer | Kaelyn Uhrain <rikka@google.com> | 2012-11-12 23:48:05 +0000 |
commit | 51ceb7bab599ea7d39d290ff5e88e4a1f0f5bc5c (patch) | |
tree | f48a80675d89be32161e03983fad72a97da6cbe1 /lib/Sema/SemaDecl.cpp | |
parent | d51db4935736fd943bfd46dfa74d41e9a3c2d41f (diff) |
Enable C++11 attribute syntax for warn_unused_result and allow it to be
applied to CXXRecordDecls, where functions with that return type will
inherit the warn_unused_result attribute.
Also includes a tiny fix (with no discernable behavior change for
existing code) to re-sync AttributeDeclKind enum and
err_attribute_wrong_decl_type with warn_attribute_wrong_decl_type since
the enum is used with both diagnostic messages to chose the correct
description.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@167783 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema/SemaDecl.cpp')
-rw-r--r-- | lib/Sema/SemaDecl.cpp | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp index 0092d5dab1..f2e840494f 100644 --- a/lib/Sema/SemaDecl.cpp +++ b/lib/Sema/SemaDecl.cpp @@ -5691,6 +5691,14 @@ Sema::ActOnFunctionDeclarator(Scope *S, Declarator &D, DeclContext *DC, ProcessDeclAttributes(S, NewFD, D, /*NonInheritable=*/false, /*Inheritable=*/true); + QualType RetType = NewFD->getResultType(); + const CXXRecordDecl *Ret = RetType->isRecordType() ? + RetType->getAsCXXRecordDecl() : RetType->getPointeeCXXRecordDecl(); + if (!NewFD->isInvalidDecl() && !NewFD->hasAttr<WarnUnusedResultAttr>() && + Ret && Ret->hasAttr<WarnUnusedResultAttr>()) { + NewFD->addAttr(new (Context) WarnUnusedResultAttr(SourceRange(), Context)); + } + if (!getLangOpts().CPlusPlus) { // Perform semantic checking on the function declaration. bool isExplicitSpecialization=false; |