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@-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@-1 {{return type 'base' is an abstract class}}
+}
+
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@-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@-1 {{return type 'base' is an abstract class}}
+}
+
_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits

Reply via email to