This is an archive of the discontinued LLVM Phabricator instance.

[clang-tidy] misc-unused-parameters: don't comment out parameter name for C code
ClosedPublic

Authored by mgehre on Jun 10 2019, 12:16 PM.

Diff Detail

Repository
rL LLVM

Event Timeline

mgehre created this revision.Jun 10 2019, 12:16 PM
Herald added a project: Restricted Project. · View Herald TranscriptJun 10 2019, 12:16 PM
Herald added a subscriber: xazax.hun. · View Herald Transcript
mgehre updated this revision to Diff 203873.Jun 10 2019, 12:17 PM

Fix rewrapped comment

lebedev.ri accepted this revision.Jun 14 2019, 3:36 PM

Seems obviously correct, with the nit.

clang-tools-extra/clang-tidy/misc/UnusedParametersCheck.cpp
141–156 ↗(On Diff #203873)

I'd recommend to instead do less confusing

// Cannot remove parameter for non-local functions.
if (Function->isExternallyVisible() ||
    !Result.SourceManager->isInMainFile(Function->getLocation()) ||
    !Indexer->getOtherRefs(Function).empty() || isOverrideMethod(Function)) {
  // It is illegal to omit parameter name here in C code, so early-out.
  if (!Result.Context->getLangOpts().CPlusPlus)
    return;

  SourceRange RemovalRange(Param->getLocation());
  // Note: We always add a space before the '/*' to not accidentally create
  // a '*/*' for pointer types, which doesn't start a comment. clang-format
  // will clean this up afterwards.
  MyDiag << FixItHint::CreateReplacement(
      RemovalRange, (Twine(" /*") + Param->getName() + "*/").str());
  return;
}
clang-tools-extra/test/clang-tidy/misc-unused-parameters.c
1–7 ↗(On Diff #203873)

This screams a separate bug to me.
Does %check_clang_tidy not check that sources, after applying fix-it's, still parse?

This revision is now accepted and ready to land.Jun 14 2019, 3:36 PM
mgehre marked an inline comment as done.Jun 16 2019, 12:43 PM
mgehre added inline comments.
clang-tools-extra/test/clang-tidy/misc-unused-parameters.c
1–7 ↗(On Diff #203873)

Unfortunately, no :-(

mgehre marked an inline comment as done.Jun 16 2019, 12:43 PM
mgehre added inline comments.
clang-tools-extra/clang-tidy/misc/UnusedParametersCheck.cpp
141–156 ↗(On Diff #203873)

Good idea, will do!

aaron.ballman accepted this revision.Jun 18 2019, 7:48 AM

LGTM!

Funny enough, I've got a paper out for WG14 to try to relax this for C2x: http://www.open-std.org/jtc1/sc22/wg14/www/docs/n2381.pdf

This revision was automatically updated to reflect the committed changes.
Herald added a project: Restricted Project. · View Herald TranscriptJun 21 2019, 2:30 PM