[cfe-commits] r123916 - in /cfe/trunk: include/clang/Sema/Sema.h lib/Sema/SemaDecl.cpp lib/Sema/SemaDeclCXX.cpp test/CXX/class.derived/class.virtual/p3-0x.cpp
Anders Carlsson
andersca at mac.com
Thu Jan 20 08:25:36 PST 2011
Author: andersca
Date: Thu Jan 20 10:25:36 2011
New Revision: 123916
URL: http://llvm.org/viewvc/llvm-project?rev=123916&view=rev
Log:
Diagnose when a virtual member function marked final is overridden.
Modified:
cfe/trunk/include/clang/Sema/Sema.h
cfe/trunk/lib/Sema/SemaDecl.cpp
cfe/trunk/lib/Sema/SemaDeclCXX.cpp
cfe/trunk/test/CXX/class.derived/class.virtual/p3-0x.cpp
Modified: cfe/trunk/include/clang/Sema/Sema.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/Sema.h?rev=123916&r1=123915&r2=123916&view=diff
==============================================================================
--- cfe/trunk/include/clang/Sema/Sema.h (original)
+++ cfe/trunk/include/clang/Sema/Sema.h Thu Jan 20 10:25:36 2011
@@ -2717,16 +2717,18 @@
bool CheckOverridingFunctionExceptionSpec(const CXXMethodDecl *New,
const CXXMethodDecl *Old);
- /// CheckOverridingFunctionAttributes - Checks whether attributes are
- /// incompatible or prevent overriding.
- bool CheckOverridingFunctionAttributes(const CXXMethodDecl *New,
- const CXXMethodDecl *Old);
-
bool CheckPureMethod(CXXMethodDecl *Method, SourceRange InitRange);
/// CheckOverrideControl - Check C++0x override control semantics.
void CheckOverrideControl(const Decl *D);
+ /// CheckForFunctionMarkedFinal - Checks whether a virtual member function
+ /// overrides a virtual member function marked 'final', according to
+ /// C++0x [class.virtual]p3.
+ bool CheckIfOverriddenFunctionIsMarkedFinal(const CXXMethodDecl *New,
+ const CXXMethodDecl *Old);
+
+
//===--------------------------------------------------------------------===//
// C++ Access Control
//
Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=123916&r1=123915&r2=123916&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Thu Jan 20 10:25:36 2011
@@ -3347,7 +3347,7 @@
if (CXXMethodDecl *OldMD = dyn_cast<CXXMethodDecl>(*I)) {
if (!CheckOverridingFunctionReturnType(MD, OldMD) &&
!CheckOverridingFunctionExceptionSpec(MD, OldMD) &&
- !CheckOverridingFunctionAttributes(MD, OldMD)) {
+ !CheckIfOverriddenFunctionIsMarkedFinal(MD, OldMD)) {
MD->addOverriddenMethod(OldMD->getCanonicalDecl());
AddedAny = true;
}
Modified: cfe/trunk/lib/Sema/SemaDeclCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclCXX.cpp?rev=123916&r1=123915&r2=123916&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclCXX.cpp Thu Jan 20 10:25:36 2011
@@ -875,6 +875,22 @@
}
}
+/// CheckIfOverriddenFunctionIsMarkedFinal - Checks whether a virtual member
+/// function overrides a virtual member function marked 'final', according to
+/// C++0x [class.virtual]p3.
+bool Sema::CheckIfOverriddenFunctionIsMarkedFinal(const CXXMethodDecl *New,
+ const CXXMethodDecl *Old) {
+ // FIXME: Get rid of FinalAttr here.
+ if (Old->hasAttr<FinalAttr>() || Old->isMarkedFinal()) {
+ Diag(New->getLocation(), diag::err_final_function_overridden)
+ << New->getDeclName();
+ Diag(Old->getLocation(), diag::note_overridden_virtual_function);
+ return true;
+ }
+
+ return false;
+}
+
/// ActOnCXXMemberDeclarator - This is invoked when a C++ class member
/// declarator is parsed. 'AS' is the access specifier, 'BW' specifies the
/// bitfield width if there is one and 'InitExpr' specifies the initializer if
@@ -6918,19 +6934,6 @@
return false;
}
-bool Sema::CheckOverridingFunctionAttributes(const CXXMethodDecl *New,
- const CXXMethodDecl *Old)
-{
- if (Old->hasAttr<FinalAttr>()) {
- Diag(New->getLocation(), diag::err_final_function_overridden)
- << New->getDeclName();
- Diag(Old->getLocation(), diag::note_overridden_virtual_function);
- return true;
- }
-
- return false;
-}
-
/// \brief Mark the given method pure.
///
/// \param Method the method to be marked pure.
Modified: cfe/trunk/test/CXX/class.derived/class.virtual/p3-0x.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/class.derived/class.virtual/p3-0x.cpp?rev=123916&r1=123915&r2=123916&view=diff
==============================================================================
--- cfe/trunk/test/CXX/class.derived/class.virtual/p3-0x.cpp (original)
+++ cfe/trunk/test/CXX/class.derived/class.virtual/p3-0x.cpp Thu Jan 20 10:25:36 2011
@@ -40,3 +40,14 @@
template struct B<int>; // expected-note {{in instantiation of template class 'Test3::B<int>' requested here}}
}
+
+namespace Test4 {
+struct B {
+ virtual void f() const final; // expected-note {{overridden virtual function is here}}
+};
+
+struct D : B {
+ void f() const; // expected-error {{declaration of 'f' overrides a 'final' function}}
+};
+
+}
More information about the cfe-commits
mailing list