[PATCH] SemaChecking: return type validation for member functions
Saleem Abdulrasool
compnerd at compnerd.org
Sun Jan 5 23:14:09 PST 2014
Avoid double diagnostics generation for constructors.
Hi rsmith,
http://llvm-reviews.chandlerc.com/D2514
CHANGE SINCE LAST DIFF
http://llvm-reviews.chandlerc.com/D2514?vs=6361&id=6362#toc
Files:
lib/Sema/SemaExprCXX.cpp
test/Analysis/PR18393.cpp
Index: lib/Sema/SemaExprCXX.cpp
===================================================================
--- lib/Sema/SemaExprCXX.cpp
+++ lib/Sema/SemaExprCXX.cpp
@@ -4946,6 +4946,13 @@
bool IsDecltype = ExprEvalContexts.back().IsDecltype;
CXXDestructorDecl *Destructor = IsDecltype ? 0 : LookupDestructor(RD);
+ if (!IsDecltype && RD->isAbstract() && !isa<CXXConstructExpr>(E)) {
+ Diag(E->getExprLoc(), diag::err_abstract_type_in_decl)
+ << Sema::AbstractReturnType << RT->desugar();
+ DiagnoseAbstractType(RD);
+ return Owned(E);
+ }
+
if (Destructor) {
MarkFunctionReferenced(E->getExprLoc(), Destructor);
CheckDestructorAccess(E->getExprLoc(), Destructor,
Index: test/Analysis/PR18393.cpp
===================================================================
--- /dev/null
+++ test/Analysis/PR18393.cpp
@@ -0,0 +1,26 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+// PR18393
+
+struct base {
+ virtual void method() = 0;
+ // expected-note at -1 {{unimplemented pure virtual method 'method' in 'base'}}
+};
+
+struct derived : base {
+ virtual void method();
+};
+
+struct holder {
+ holder() : d_() {}
+ base get() const { return d_; }
+ const derived d_;
+};
+
+void function(const base &);
+
+void test() {
+ holder h;
+ function(h.get());
+ // expected-error at -1 {{return type 'base' is an abstract class}}
+}
+
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D2514.2.patch
Type: text/x-patch
Size: 1358 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20140105/5700a4ce/attachment.bin>
More information about the cfe-commits
mailing list