[cfe-commits] r167873 - in /cfe/trunk: lib/Sema/SemaDecl.cpp test/SemaCXX/warn-unused-result.cpp

Jordan Rose jordan_rose at apple.com
Tue Nov 13 13:40:03 PST 2012


That doesn't seem right. Factory methods? operator-? I think assignment operators are the special case, not 'returning an instance'.

…except for operator<< on streams. Hm.

Jordan


On Nov 13, 2012, at 13:23 , Kaelyn Uhrain <rikka at google.com> wrote:

> Author: rikka
> Date: Tue Nov 13 15:23:31 2012
> New Revision: 167873
> 
> URL: http://llvm.org/viewvc/llvm-project?rev=167873&view=rev
> Log:
> For classes that have the warn_unused_result attribute, don't apply the
> attribute to the class' methods even when they return an instance of the
> class (e.g. assignment operators).
> 
> Modified:
>    cfe/trunk/lib/Sema/SemaDecl.cpp
>    cfe/trunk/test/SemaCXX/warn-unused-result.cpp
> 
> Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=167873&r1=167872&r2=167873&view=diff
> ==============================================================================
> --- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
> +++ cfe/trunk/lib/Sema/SemaDecl.cpp Tue Nov 13 15:23:31 2012
> @@ -5696,7 +5696,11 @@
>       RetType->getAsCXXRecordDecl() : RetType->getPointeeCXXRecordDecl();
>   if (!NewFD->isInvalidDecl() && !NewFD->hasAttr<WarnUnusedResultAttr>() &&
>       Ret && Ret->hasAttr<WarnUnusedResultAttr>()) {
> -    NewFD->addAttr(new (Context) WarnUnusedResultAttr(SourceRange(), Context));
> +    const CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(NewFD);
> +    if (!(MD && MD->getCorrespondingMethodInClass(Ret, true))) {
> +      NewFD->addAttr(new (Context) WarnUnusedResultAttr(SourceRange(),
> +                                                        Context));
> +    }
>   }
> 
>   if (!getLangOpts().CPlusPlus) {
> 
> Modified: cfe/trunk/test/SemaCXX/warn-unused-result.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/warn-unused-result.cpp?rev=167873&r1=167872&r2=167873&view=diff
> ==============================================================================
> --- cfe/trunk/test/SemaCXX/warn-unused-result.cpp (original)
> +++ cfe/trunk/test/SemaCXX/warn-unused-result.cpp Tue Nov 13 15:23:31 2012
> @@ -46,6 +46,12 @@
> namespace warn_unused_CXX11 {
> struct [[clang::warn_unused_result]] Status {
>   bool ok() const;
> +  Status& operator=(const Status& x);
> +  inline void Update(const Status& new_status) {
> +    if (ok()) {
> +      *this = new_status; //no-warning
> +    }
> +  }
> };
> Status DoSomething();
> Status& DoSomethingElse();
> 
> 
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits





More information about the cfe-commits mailing list