[PATCH] Fix for PR18393 - emit error when abstract type is returned by value
Robert Matusewicz
matekm at gmail.com
Sun Aug 3 07:03:36 PDT 2014
Clang doesn't emit error message when return type of declared method is an abstract type. This error is catched when method is defined but it would be cool to catch it as soon as possible.
This patch removes check that prevented checking if method return type is abstract in record context. I also added additional test to prevent regression in this context.
Br,
Robert
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;
+ };
+
+ struct B {
+ A f(); // expected-error {{return type 'PR18393::A' is an abstract class}}
+ };
+}
+
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D4769.12146.patch
Type: text/x-patch
Size: 1185 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20140803/22661991/attachment.bin>
More information about the cfe-commits
mailing list