From bbff538e9dac515081a11ddf20de5bd5eeccba62 Mon Sep 17 00:00:00 2001 From: Haojian Wu Date: Wed, 3 Feb 2016 17:21:44 +0000 Subject: [PATCH] [clang-tidy] Fix a crash issue on misc-virtual-near-miss check. Summary: The crash is caused by triggering a Assertion failed in DeclCXX.h when the check detects non-defined class return type in a class method declaration. Reviewers: congliu, alexfh Subscribers: cfe-commits Differential Revision: http://reviews.llvm.org/D16854 llvm-svn: 259668 --- clang-tools-extra/clang-tidy/misc/VirtualNearMissCheck.cpp | 3 +++ clang-tools-extra/test/clang-tidy/misc-virtual-near-miss.cpp | 6 ++++++ 2 files changed, 9 insertions(+) diff --git a/clang-tools-extra/clang-tidy/misc/VirtualNearMissCheck.cpp b/clang-tools-extra/clang-tidy/misc/VirtualNearMissCheck.cpp index 24aea8c2..ddec9d9 100644 --- a/clang-tools-extra/clang-tidy/misc/VirtualNearMissCheck.cpp +++ b/clang-tools-extra/clang-tidy/misc/VirtualNearMissCheck.cpp @@ -72,6 +72,9 @@ static bool checkOverridingFunctionReturnType(const ASTContext *Context, if (DRD == nullptr || BRD == nullptr) return false; + if (!DRD->hasDefinition() || !BRD->hasDefinition()) + return false; + if (DRD == BRD) return true; diff --git a/clang-tools-extra/test/clang-tidy/misc-virtual-near-miss.cpp b/clang-tools-extra/test/clang-tidy/misc-virtual-near-miss.cpp index 4e211a6..c3f2e62 100644 --- a/clang-tools-extra/test/clang-tidy/misc-virtual-near-miss.cpp +++ b/clang-tools-extra/test/clang-tidy/misc-virtual-near-miss.cpp @@ -1,10 +1,14 @@ // RUN: %check_clang_tidy %s misc-virtual-near-miss %t +class NoDefinedClass1; +class NoDefinedClass2; + struct Base { virtual void func(); virtual void gunk(); virtual ~Base(); virtual Base &operator=(const Base &); + virtual NoDefinedClass1 *f(); }; struct Derived : Base { @@ -24,6 +28,8 @@ struct Derived : Base { // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: method 'Derived::fun' has {{.*}} 'Base::func' Derived &operator==(const Base &); // Should not warn: operators are ignored. + + virtual NoDefinedClass2 *f1(); // Should not crash: non-defined class return type is ignored. }; typedef Derived derived_type; -- 2.7.4