Page MenuHomePhabricator

[Clang][Sema] better -Wcast-function-type diagnose for pointer parameters and parameters with cv-qualifiers
Needs ReviewPublic

Authored by ychen on Apr 5 2021, 3:22 PM.


  1. Skip diagnosing all pointer-like parameters.
  2. Replace Context.hasSameUnqualifiedType with Context.hasSimilarType.
  3. Add corresponding tests.

After some thoughts, I think we could add the following extension in the
future (probably under an additional flag such as `-Wcast-function-type=2)
according to user feedbacks for the reasons: 1) users could use
void(*)(void) to explicitly override checks (for example:; 2) these checks could
hide real bugs that users may want to catch; 3) using void(*)(void)
makes following extension worthwhile only when a codebase uses these
patterns on a large scale which seems unlikely.

(GCC does not do the following)

  • allow integer promotion (void(int) -> void(char))
  • allow arbitrary pointer-to-member conversion


Diff Detail

Event Timeline

ychen requested review of this revision.Apr 5 2021, 3:22 PM
ychen created this revision.
Herald added a project: Restricted Project. · View Herald TranscriptApr 5 2021, 3:22 PM
Herald added a subscriber: cfe-commits. · View Herald Transcript
ychen edited the summary of this revision. (Show Details)Apr 5 2021, 3:23 PM