Implement the first half of [dcl.attr.override]p6.

llvm-svn: 116709
This commit is contained in:
Anders Carlsson 2010-10-18 16:24:27 +00:00
parent 1f1f63a698
commit 778ca32c88
3 changed files with 71 additions and 0 deletions

View File

@ -834,6 +834,9 @@ def err_final_base : Error<
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">;

View File

@ -3228,6 +3228,29 @@ CheckClassMemberNameAttributes(Sema& SemaRef, const FunctionDecl *FD) {
<< 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*

View File

@ -0,0 +1,45 @@
// 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'}}
};
}
}