On Sunday, January 31, 2016, Kim Gräsman <kim.gras...@gmail.com> wrote:
> Hi David, > > Should this be guarded by if(cxx14)? I think the complete type was > required by earlier standards. > It is the same issue as CWG defect report 1250: http://wg21.cmeerw.net/cwg/issue1250 I forget how to tell how far back a DR applies but I'd guess this one goes as far back as C++11. > - Kim > Den 26 jan 2016 2:40 fm skrev "David Majnemer via cfe-commits" < > cfe-commits@lists.llvm.org > <javascript:_e(%7B%7D,'cvml','cfe-commits@lists.llvm.org');>>: > >> 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 >> <javascript:_e(%7B%7D,'cvml','cfe-commits@lists.llvm.org');> >> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits >> >
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits