[PATCH] D82728: [clang] Add -Wsuggest-override

Logan Smith via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Sun Jun 28 13:27:40 PDT 2020


logan-5 created this revision.
logan-5 added a reviewer: rsmith.
logan-5 added a project: clang.
Herald added a subscriber: cfe-commits.

This patch adds `-Wsuggest-override`, which allows for more aggressive enforcement of modern C++ best practices, as well as better compatibility with gcc, which has had its own `-Wsuggest-override` since version 5.1.

Clang already has `-Winconsistent-missing-override`, which only warns in the case where there is at least one function already marked `override` in a class. This warning strengthens that warning by suggesting the `override` keyword regardless of whether it is already present anywhere.

The text between suggest-override and inconsistent-missing-override is now shared, using `TextSubstitution` for the entire diagnostic text. I'm not sure if there is a better way to accomplish this.

This patch as written behaves strangely with `-Wno-inconsistent-missing-override -Wsuggest-override`. In that case, a warning is //only// generated if there are no overrides already marked (because inconsistent-missing-override 'wins' when choosing which diagnostic to emit). However, this is a fairly nonsensical use case, so in my opinion it's fine.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D82728

Files:
  clang/include/clang/Basic/DiagnosticGroups.td
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Sema/Sema.h
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/test/SemaCXX/warn-suggest-destructor-override
  clang/test/SemaCXX/warn-suggest-override

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D82728.273970.patch
Type: text/x-patch
Size: 7987 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200628/80476284/attachment-0001.bin>


More information about the cfe-commits mailing list