Index: clang-tools-extra/trunk/clang-tidy/misc/VirtualNearMissCheck.cpp =================================================================== --- clang-tools-extra/trunk/clang-tidy/misc/VirtualNearMissCheck.cpp +++ clang-tools-extra/trunk/clang-tidy/misc/VirtualNearMissCheck.cpp @@ -72,6 +72,9 @@ if (DRD == nullptr || BRD == nullptr) return false; + if (!DRD->hasDefinition() || !BRD->hasDefinition()) + return false; + if (DRD == BRD) return true; Index: clang-tools-extra/trunk/test/clang-tidy/misc-virtual-near-miss.cpp =================================================================== --- clang-tools-extra/trunk/test/clang-tidy/misc-virtual-near-miss.cpp +++ clang-tools-extra/trunk/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 @@ // 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;