[cfe-commits] r124047 - in /cfe/trunk: lib/Sema/SemaDeclCXX.cpp test/CXX/class.derived/p8-0x.cpp

Anders Carlsson andersca at mac.com
Sat Jan 22 14:23:37 PST 2011


Author: andersca
Date: Sat Jan 22 16:23:37 2011
New Revision: 124047

URL: http://llvm.org/viewvc/llvm-project?rev=124047&view=rev
Log:
Implement [class.derived]p8.


Added:
    cfe/trunk/test/CXX/class.derived/p8-0x.cpp
Modified:
    cfe/trunk/lib/Sema/SemaDeclCXX.cpp

Modified: cfe/trunk/lib/Sema/SemaDeclCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclCXX.cpp?rev=124047&r1=124046&r2=124047&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclCXX.cpp Sat Jan 22 16:23:37 2011
@@ -886,6 +886,26 @@
       << MD->getDeclName();
     return;
   }
+
+  // C++0x [class.derived]p8:
+  //   In a class definition marked with the class-virt-specifier explicit,
+  //   if a virtual member function that is neither implicitly-declared nor a 
+  //   destructor overrides a member function of a base class and it is not
+  //   marked with the virt-specifier override, the program is ill-formed.
+  if (MD->getParent()->isMarkedExplicit() && !isa<CXXDestructorDecl>(MD) &&
+      HasOverriddenMethods && !MD->isMarkedOverride()) {
+    llvm::SmallVector<const CXXMethodDecl*, 4> 
+      OverriddenMethods(MD->begin_overridden_methods(), 
+                        MD->end_overridden_methods());
+
+    Diag(MD->getLocation(), diag::err_function_overriding_without_override)
+      << MD->getDeclName() 
+      << (unsigned)OverriddenMethods.size();
+
+    for (unsigned I = 0; I != OverriddenMethods.size(); ++I)
+      Diag(OverriddenMethods[I]->getLocation(),
+           diag::note_overridden_virtual_function);
+  }
 }
 
 /// CheckIfOverriddenFunctionIsMarkedFinal - Checks whether a virtual member 

Added: cfe/trunk/test/CXX/class.derived/p8-0x.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/class.derived/p8-0x.cpp?rev=124047&view=auto
==============================================================================
--- cfe/trunk/test/CXX/class.derived/p8-0x.cpp (added)
+++ cfe/trunk/test/CXX/class.derived/p8-0x.cpp Sat Jan 22 16:23:37 2011
@@ -0,0 +1,22 @@
+// RUN: %clang_cc1 %s -fsyntax-only -verify -std=c++0x
+
+namespace Test1 {
+
+struct A {
+  virtual void f(); // expected-note {{overridden virtual function is here}}
+};
+
+struct B explicit : A {
+  virtual void f(); // expected-error {{overrides function without being marked 'override'}}
+};
+
+struct C {
+  virtual ~C();
+};
+
+struct D explicit : C {
+  virtual ~D();
+};
+
+}
+





More information about the cfe-commits mailing list