[PATCH] Fix for PR18393 - emit error when abstract type is returned by value

Arthur O'Dwyer arthur.j.odwyer at gmail.com
Sun Aug 3 09:33:44 PDT 2014


Does this reject valid C++ code involving templates?  I.e., is there
any wording in the Standard that says this kind of code *can* be
rejected, or are these declarations expected to compile quietly?

class C { typedef C type; virtual void foo() = 0; };
template<class T> class X { T::type mytype(); };  // no definition of
mytype is necessary, nor possible
decltype(X<C>::mytype()) *p = nullptr;

I don't see anything wrong with returning an instance of an abstract
type, in principle. The type system shouldn't care about that sort of
thing.

–Arthur


On Sun, Aug 3, 2014 at 7:25 AM, Robert Matusewicz <matekm at gmail.com> wrote:
> Update diff as tests were not complete - check for note was missing
>
> http://reviews.llvm.org/D4769
>
> Files:
>   lib/Sema/SemaDecl.cpp
>   test/SemaCXX/abstract.cpp
>
> Index: lib/Sema/SemaDecl.cpp
> ===================================================================
> --- lib/Sema/SemaDecl.cpp
> +++ lib/Sema/SemaDecl.cpp
> @@ -6496,8 +6496,7 @@
>    // Check that the return type is not an abstract class type.
>    // For record types, this is done by the AbstractClassUsageDiagnoser once
>    // the class has been completely parsed.
> -  if (!DC->isRecord() &&
> -      SemaRef.RequireNonAbstractType(
> +  if (SemaRef.RequireNonAbstractType(
>            D.getIdentifierLoc(), R->getAs<FunctionType>()->getReturnType(),
>            diag::err_abstract_type_in_decl, SemaRef.AbstractReturnType))
>      D.setInvalidType();
> Index: test/SemaCXX/abstract.cpp
> ===================================================================
> --- test/SemaCXX/abstract.cpp
> +++ test/SemaCXX/abstract.cpp
> @@ -307,3 +307,14 @@
>      RedundantInit() : A(0) {} // expected-warning {{initializer for virtual base class 'pr16659::A' of abstract class 'RedundantInit' will never be used}}
>    };
>  }
> +
> +namespace PR18393 {
> +  struct A {
> +      virtual void f() = 0; // expected-note {{unimplemented pure virtual method 'f' in 'A'}}
> +  };
> +
> +  struct B {
> +      A f(); // expected-error {{return type 'PR18393::A' is an abstract class}}
> +  };
> +}
> +
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
>




More information about the cfe-commits mailing list