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

Stephen Lin swlin at post.harvard.edu
Mon Mar 18 10:56:06 PDT 2013


Hi,

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.

Stephen
-------------- next part --------------
A non-text attachment was scrubbed...
Name: unqual-friend-dead-code.patch
Type: text/x-diff
Size: 870 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20130318/4faf8591/attachment.patch>


More information about the cfe-commits mailing list