Author: majnemer Date: Mon Jan 25 19:37:01 2016 New Revision: 258768 URL: http://llvm.org/viewvc/llvm-project?rev=258768&view=rev Log: [Sema] Incomplete types are OK for covariant returns
Per C++14 [class.virtual]p8, it is OK for the return type's class type to be incomplete so long as the return type is the same between the base and complete classes. This fixes PR26297. Modified: cfe/trunk/lib/Sema/SemaDeclCXX.cpp cfe/trunk/test/SemaCXX/virtual-override.cpp Modified: cfe/trunk/lib/Sema/SemaDeclCXX.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclCXX.cpp?rev=258768&r1=258767&r2=258768&view=diff ============================================================================== --- cfe/trunk/lib/Sema/SemaDeclCXX.cpp (original) +++ cfe/trunk/lib/Sema/SemaDeclCXX.cpp Mon Jan 25 19:37:01 2016 @@ -13020,19 +13020,20 @@ bool Sema::CheckOverridingFunctionReturn return true; } - // C++ [class.virtual]p6: - // If the return type of D::f differs from the return type of B::f, the - // class type in the return type of D::f shall be complete at the point of - // declaration of D::f or shall be the class type D. - if (const RecordType *RT = NewClassTy->getAs<RecordType>()) { - if (!RT->isBeingDefined() && - RequireCompleteType(New->getLocation(), NewClassTy, - diag::err_covariant_return_incomplete, - New->getDeclName())) - return true; - } - if (!Context.hasSameUnqualifiedType(NewClassTy, OldClassTy)) { + // C++14 [class.virtual]p8: + // If the class type in the covariant return type of D::f differs from + // that of B::f, the class type in the return type of D::f shall be + // complete at the point of declaration of D::f or shall be the class + // type D. + if (const RecordType *RT = NewClassTy->getAs<RecordType>()) { + if (!RT->isBeingDefined() && + RequireCompleteType(New->getLocation(), NewClassTy, + diag::err_covariant_return_incomplete, + New->getDeclName())) + return true; + } + // Check if the new class derives from the old class. if (!IsDerivedFrom(New->getLocation(), NewClassTy, OldClassTy)) { Diag(New->getLocation(), diag::err_covariant_return_not_derived) Modified: cfe/trunk/test/SemaCXX/virtual-override.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/virtual-override.cpp?rev=258768&r1=258767&r2=258768&view=diff ============================================================================== --- cfe/trunk/test/SemaCXX/virtual-override.cpp (original) +++ cfe/trunk/test/SemaCXX/virtual-override.cpp Mon Jan 25 19:37:01 2016 @@ -289,3 +289,15 @@ namespace PR8168 { static void foo() {} // expected-error{{'static' member function 'foo' overrides a virtual function}} }; } + +namespace PR26297 { +struct Incomplete; + +struct Base { + virtual const Incomplete *meow() = 0; +}; + +struct Derived : Base { + virtual Incomplete *meow() override { return nullptr; } +}; +} _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits