def err_override_function_not_overriding : Error<
"%0 marked 'override' but does not override any member functions">;
+def err_function_overriding_without_override : Error<
+ "%0 overrides function%s1 without being marked 'override'">;
+
// C++0x scoped enumerations
def err_enum_invalid_underlying : Error<
"non-integral type %0 is an invalid underlying type">;
<< MD->getDeclName();
return;
}
+
+ if (!MD->getParent()->hasAttr<BaseCheckAttr>())
+ return;
+
+ /// C++ [dcl.attr.override]p6:
+ /// In a class definition marked base_check, 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 override, the
+ /// program is ill-formed.
+ if (HasOverriddenMethods && !HasOverrideAttr && !MD->isImplicit() &&
+ !isa<CXXDestructorDecl>(MD)) {
+ llvm::SmallVector<const CXXMethodDecl*, 4>
+ OverriddenMethods(MD->begin_overridden_methods(),
+ MD->end_overridden_methods());
+
+ SemaRef.Diag(MD->getLocation(),
+ diag::err_function_overriding_without_override)
+ << MD->getDeclName() << (unsigned)OverriddenMethods.size();
+
+ for (unsigned I = 0; I != OverriddenMethods.size(); ++I)
+ SemaRef.Diag(OverriddenMethods[I]->getLocation(),
+ diag::note_overridden_virtual_function);
+ }
}
NamedDecl*
--- /dev/null
+// RUN: %clang_cc1 -std=c++0x -fsyntax-only -verify %s
+
+namespace Override {
+
+namespace Test1 {
+
+struct A {
+ virtual ~A();
+};
+
+struct [[base_check]] B : A {
+ virtual ~B();
+};
+
+}
+
+namespace Test2 {
+
+struct A {
+ virtual void f(); // expected-note {{overridden virtual function is here}}
+};
+
+struct [[base_check]] B : A {
+ virtual void f(); // expected-error {{'f' overrides function without being marked 'override'}}
+};
+
+}
+
+namespace Test3 {
+
+struct A {
+ virtual void f(); // expected-note {{overridden virtual function is here}}
+};
+
+struct B {
+ virtual void f(); // expected-note {{overridden virtual function is here}}
+};
+
+struct [[base_check]] C : A, B {
+ virtual void f(); // expected-error {{'f' overrides functions without being marked 'override'}}
+};
+
+}
+
+}