This is an archive of the discontinued LLVM Phabricator instance.

[NFC] Prevent shadowing a variable declared in `if`
ClosedPublic

Authored by ken-matsui on Apr 27 2022, 2:08 PM.

Details

Summary

Prevents confusion over which S is referenced in the final else branch if such use is added.

Diff Detail

Event Timeline

ken-matsui created this revision.Apr 27 2022, 2:08 PM
Herald added a project: Restricted Project. · View Herald TranscriptApr 27 2022, 2:08 PM
ken-matsui requested review of this revision.Apr 27 2022, 2:08 PM
Herald added a project: Restricted Project. · View Herald TranscriptApr 27 2022, 2:08 PM
Herald added a subscriber: cfe-commits. · View Herald Transcript
hubert.reinterpretcast retitled this revision from Prevent shadowing a variable declared in `if` to [NFC] Prevent shadowing a variable declared in `if`.Apr 27 2022, 9:07 PM

@ken-matsui, can you provide some rationale for the change (got compiler warning/error)?

@hubert.reinterpretcast,

Sorry to have missed providing a summary.

In most cases, shadowing a declaration of a local variable should be avoided to prevent making others confused and mistakes because we need to figure out the boundaries of the declaration. In this case, the variable declared by const char *S in if can be accessed by every branch. That means that declarations in else if had shadowed the declaration in if, so I changed them to use the same declaration used in if.

@hubert.reinterpretcast,

Sorry to have missed providing a summary.

You can still provide one by using the "Edit Revision" link.

I suggest something like:
Prevents confusion over which S is referenced in the final else branch if such a use is added.

ken-matsui edited the summary of this revision. (Show Details)Apr 28 2022, 8:10 AM

@hubert.reinterpretcast,

Thank you for your suggestion! I’ve updated the summary.

LGTM; thanks for the patch!

This revision is now accepted and ready to land.Apr 28 2022, 8:17 AM

Thank you for your review!

ken-matsui added a comment.EditedApr 28 2022, 8:25 AM

@hubert.reinterpretcast

Sorry, I'm a newbie here, but is there anything I should do after getting approved?

(I could not execute arc land due to 403 error to the llvm-project)

remote: Permission to llvm/llvm-project.git denied to ken-matsui.
fatal: unable to access 'https://github.com/llvm/llvm-project.git/': The requested URL returned error: 403

@hubert.reinterpretcast

Sorry, I'm a newbie here, but is there anything I should do after getting approved?

I'm not sure if the instructions are a bit out-of-date: https://llvm.org/docs/DeveloperPolicy.html#obtaining-commit-access

If you intend to contribute going forward, the idea would be to get a few patches approved and committed on your behalf and then to request commit access. Until you have commit access, you will need to ask people on the review to help you commit.

I can commit this patch for you.

@hubert.reinterpretcast

I see. Thank you for the detailed information!

Could you please commit this patch?

Thank you!

Thanks in turn.