alexfh added inline comments.

================
Comment at: clang-tidy/misc/VirtualNearMissCheck.cpp:85
@@ +84,3 @@
+  }else {
+    return false;
+  }
----------------
congliu wrote:
> alexfh wrote:
> > What if both return types are not references and are not pointers? Why do 
> > you return `false` in this case?
> This is to deal with an special case of C++ override. Usually the return type 
> of the override and overriden should be the same. The exception is that the 
> return type ban be a reference (or pointer) to the class themselves. For 
> example, 
>   class Base{
>     virtual Base* func();
>   };
>   class Derived : Base{
>     virtual Derived* func();
>   };
> In this case, the Derived::func() does override Base::func(), even though the 
> return type are not the same.
> So if the return types are not the same (line 72 assured that), and are not 
> both references (or pointers), we can rule out the possibility of override, 
> and therefore return false.
It looks like you're talking about the concept of covariance described in 
[class.virtual] p7. And you seem to be getting it wrong: the return type 
doesn't need to be a pointer/reference to the class defining the method. Here's 
the relevant quote from the standard:

> The return type of an overriding function shall be either identical to the 
> return type of the overridden
> function or covariant with the classes of the functions. If a function D::f 
> overrides a function B::f, the
> return types of the functions are covariant if they satisfy the following 
> criteria:
> — both are pointers to classes, both are lvalue references to classes, or 
> both are rvalue references to
> classes115
> — the class in the return type of B::f is the same class as the class in the 
> return type of D::f, or is an
> unambiguous and accessible direct or indirect base class of the class in the 
> return type of D::f
> — both pointers or references have the same cv-qualification and the class 
> type in the return type of D::f
> has the same cv-qualification as or less cv-qualification than the class type 
> in the return type of B::f.

Please change your code to implement this concept correctly.


http://reviews.llvm.org/D15823



_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to