[PATCH] D16377: Ensure virtual-near-miss does not crash on functions without names
Alexander Kornienko via cfe-commits
cfe-commits at lists.llvm.org
Fri Jan 22 14:37:42 PST 2016
Should be fixed in http://reviews.llvm.org/D16179.
On Jan 20, 2016 23:55, "Aaron Ballman" <aaron.ballman at gmail.com> wrote:
> aaron.ballman updated this revision to Diff 45451.
> aaron.ballman added a comment.
>
> Now checking that both the base *and* the derived functions have names.
>
>
> http://reviews.llvm.org/D16377
>
> Files:
> clang-tidy/misc/VirtualNearMissCheck.cpp
> test/clang-tidy/misc-virtual-near-miss.cpp
>
> Index: test/clang-tidy/misc-virtual-near-miss.cpp
> ===================================================================
> --- test/clang-tidy/misc-virtual-near-miss.cpp
> +++ test/clang-tidy/misc-virtual-near-miss.cpp
> @@ -63,3 +63,20 @@
> private:
> void funk(); // Should not warn: access qualifers don't match.
> };
> +
> +namespace {
> +// Ensure this code does not crash due to special member functions.
> +class _Facet_base {
> +public:
> + virtual ~_Facet_base() noexcept {}
> +};
> +
> +class facet : public _Facet_base {
> +protected:
> + virtual ~facet() noexcept {}
> +
> +public:
> + facet(const facet&) = delete;
> + facet& operator=(const facet&) = delete;
> +};
> +}
> Index: clang-tidy/misc/VirtualNearMissCheck.cpp
> ===================================================================
> --- clang-tidy/misc/VirtualNearMissCheck.cpp
> +++ clang-tidy/misc/VirtualNearMissCheck.cpp
> @@ -244,8 +244,16 @@
> if (isOverriddenByDerivedClass(BaseMD, DerivedRD))
> continue;
>
> + // If the function has an identifier for a name, then use that
> + // identifier to determine the edit distance. If the function is a
> + // special member function without an identifier, assume the edit
> + // distance is nonzero to determine whether the signature is a
> near
> + // miss or not.
> unsigned EditDistance =
> - BaseMD->getName().edit_distance(DerivedMD->getName());
> + (BaseMD->getDeclName().isIdentifier() &&
> + DerivedMD->getDeclName().isIdentifier())
> + ? BaseMD->getName().edit_distance(DerivedMD->getName())
> + : 1;
> if (EditDistance > 0 && EditDistance <= EditDistanceThreshold) {
> if (checkOverrideWithoutName(Context, BaseMD, DerivedMD)) {
> // A "virtual near miss" is found.
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20160122/32134902/attachment.html>
More information about the cfe-commits
mailing list