The fixit int square(int /*num*/) yields error: parameter name omitted for C code. Enable it only for C++ code.
Details
Details
- Reviewers
klimek ilya-biryukov lebedev.ri aaron.ballman - Commits
- rGeeb3f99d23c2: [clang-tidy] misc-unused-parameters: don't comment out parameter name for C code
rCTE364106: [clang-tidy] misc-unused-parameters: don't comment out parameter name for C code
rL364106: [clang-tidy] misc-unused-parameters: don't comment out parameter name for C code
Diff Detail
Diff Detail
- Repository
- rL LLVM
Event Timeline
Comment Actions
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. |
| clang-tools-extra/test/clang-tidy/misc-unused-parameters.c | ||
|---|---|---|
| 1–7 ↗ | (On Diff #203873) | Unfortunately, no :-( |
| clang-tools-extra/clang-tidy/misc/UnusedParametersCheck.cpp | ||
|---|---|---|
| 141–156 ↗ | (On Diff #203873) | Good idea, will do! |
Comment Actions
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