[PATCH] Remove dead code (check for impossible condition) in Sema::ActOnFriendFunctionDecl

John McCall rjmccall at apple.com
Tue Mar 19 22:06:28 PDT 2013


On Mar 18, 2013, at 10:56 AM, Stephen Lin <swlin at post.harvard.edu> wrote:
> I found code in Sema::ActOnFriendFunctionDecl() which I am almost sure
> is dead and would like to remove it.
> 
> The code in question is the following check:
> 
>    if (!Previous.empty() && DC->Equals(CurContext))
>      Diag(DS.getFriendSpecLoc(),
>           getLangOpts().CPlusPlus11 ?
>             diag::warn_cxx98_compat_friend_is_member :
>             diag::err_friend_is_member);
> 
> which happens immediately after this loop:
> 
>    DC = CurContext;
>    while (true) {
>      while (DC->isRecord() || DC->isTransparentContext())
>        DC = DC->getParent();
> 
>      LookupQualifiedName(Previous, DC);
> 
>      // TODO: decide what we think about using declarations.
>      if (isLocal || !Previous.empty())
>        break;
> 
>      if (isTemplateId) {
>        if (isa<TranslationUnitDecl>(DC)) break;
>      } else {
>        if (DC->isFileContext()) break;
>      }
>      DC = DC->getParent();
>    }
> 
> There doesn't seem to be any possibility that DC->Equals(CurContext)
> after this loop, since friends can only be declared in records; in any
> case the error given only makes sense in a record context anyway. (The
> same check is also present in another branch, but that one is OK since
> it involves qualified names.)
> 
> Please let me know if I am correct and if this is OK to be patched.

I agree with your analysis.  Assuming that it doesn't change any test cases,
feel free to take it out.

John.



More information about the cfe-commits mailing list