Fix an obvious goof that caused us to only see the top level of return types
when checking for covariance. Added some fun test cases, fixes PR6110.
This felt obvious enough to just commit. ;] Let me know if anything needs
tweaking.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@94173 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Sema/SemaDeclCXX.cpp b/lib/Sema/SemaDeclCXX.cpp
index 12b4565..289c0e0 100644
--- a/lib/Sema/SemaDeclCXX.cpp
+++ b/lib/Sema/SemaDeclCXX.cpp
@@ -5622,13 +5622,13 @@
QualType NewClassTy, OldClassTy;
/// Both types must be pointers or references to classes.
- if (PointerType *NewPT = dyn_cast<PointerType>(NewTy)) {
- if (PointerType *OldPT = dyn_cast<PointerType>(OldTy)) {
+ if (PointerType *NewPT = dyn_cast<PointerType>(CNewTy)) {
+ if (PointerType *OldPT = dyn_cast<PointerType>(COldTy)) {
NewClassTy = NewPT->getPointeeType();
OldClassTy = OldPT->getPointeeType();
}
- } else if (ReferenceType *NewRT = dyn_cast<ReferenceType>(NewTy)) {
- if (ReferenceType *OldRT = dyn_cast<ReferenceType>(OldTy)) {
+ } else if (ReferenceType *NewRT = dyn_cast<ReferenceType>(CNewTy)) {
+ if (ReferenceType *OldRT = dyn_cast<ReferenceType>(COldTy)) {
NewClassTy = NewRT->getPointeeType();
OldClassTy = OldRT->getPointeeType();
}
diff --git a/test/SemaCXX/virtual-override.cpp b/test/SemaCXX/virtual-override.cpp
index 4fdac85..a3d3f20 100644
--- a/test/SemaCXX/virtual-override.cpp
+++ b/test/SemaCXX/virtual-override.cpp
@@ -197,3 +197,20 @@
virtual Derived<int>* Method();
};
}
+
+// Look through template types and typedefs to see whether return types are
+// pointers or references.
+namespace PR6110 {
+ class Base {};
+ class Derived : public Base {};
+
+ typedef Base* BaseP;
+ typedef Derived* DerivedP;
+
+ class X { virtual BaseP f(); };
+ class X1 : public X { virtual DerivedP f(); };
+
+ template <typename T> class Y { virtual T f(); };
+ template <typename T1, typename T> class Y1 : public Y<T> { virtual T1 f(); };
+ Y1<Derived*, Base*> y;
+}