This is an archive of the discontinued LLVM Phabricator instance.

[clang-tidy] Silence modernize-redundant-void-arg in the case of vexing parses
Needs ReviewPublic

Authored by george.burgess.iv on May 31 2022, 5:09 PM.

Details

Summary

Clang's -Wvexing-parse is enabled by default. When the vexing statement was _intended_ to be interpreted as a function that takes zero arguments, the function's declaration can be rewritten as T foo(void); to silence -Wvexing-parse. This workaround seems to upset clang-tidy.

Given my own lack of understanding of the corners of C++ parsing, I'm... not entirely confident that this patch catches everything && has no unintended side-effects. The bits that -Wvexing-parse depends upon are stored within DeclaratorChunk::FunctionTypeInfos, which seem to only exist during AST formation, so it's not clear to me how to directly get at that information from clang-tidy.

Diff Detail

Event Timeline

Herald added a project: Restricted Project. · View Herald TranscriptMay 31 2022, 5:09 PM
george.burgess.iv requested review of this revision.May 31 2022, 5:09 PM
LegalizeAdulthood requested changes to this revision.Jun 22 2022, 2:13 PM

Clang-Tidy tests and docs have moved to module subdirectories.

Please rebase this onto main:HEAD and:

  • fold your changes into the appropriate subdirs, stripping the module prefix from new files.
  • make the target check-clang-extra to validate your tests
  • make the target docs-clang-tools-html to validate any docs changes
This revision now requires changes to proceed.Jun 22 2022, 2:13 PM

Rebased on top of 891319f654c102572cf7028ed04bbaf6c59e7bff as requested; ninja check-clang-extra docs-clang-tools-html passes

clang-tools-extra/test/clang-tidy/checkers/modernize/redundant-void-arg.cpp
596

This is not the only way to eliminate the vexing parse warning. For instance, if the intention is to declare foo as a function not in this translation unit, then:

void most_vexing_parse() {
  extern int foo();
}

does the trick.

Why assume that the only way to fix vexing-parse is to add (void)?