[cfe-commits] r124039 - in /cfe/trunk: include/clang/Basic/DiagnosticSemaKinds.td include/clang/Sema/Sema.h lib/Parse/ParseDeclCXX.cpp lib/Sema/SemaDecl.cpp lib/Sema/SemaDeclCXX.cpp test/CXX/class/p2-0x.cpp
Anders Carlsson
andersca at mac.com
Sat Jan 22 09:51:53 PST 2011
Author: andersca
Date: Sat Jan 22 11:51:53 2011
New Revision: 124039
URL: http://llvm.org/viewvc/llvm-project?rev=124039&view=rev
Log:
Mark classes as final or explicit. Diagnose when a class marked 'final' is used as a base.
Added:
cfe/trunk/test/CXX/class/p2-0x.cpp
Modified:
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/include/clang/Sema/Sema.h
cfe/trunk/lib/Parse/ParseDeclCXX.cpp
cfe/trunk/lib/Sema/SemaDecl.cpp
cfe/trunk/lib/Sema/SemaDeclCXX.cpp
Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=124039&r1=124038&r2=124039&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Sat Jan 22 11:51:53 2011
@@ -873,16 +873,17 @@
"'auto' return without trailing return type">;
def err_trailing_return_without_auto : Error<
"trailing return type without 'auto' return">;
-
-// C++0x attributes
-def err_repeat_attribute : Error<"'%0' attribute cannot be repeated">;
// C++0x override control
def override_keyword_only_allowed_on_virtual_member_functions : Error<
"only virtual member functions can be marked '%0'">;
-
def err_function_marked_override_not_overriding : Error<
"%0 marked 'override' but does not override any member functions">;
+def err_class_marked_final_used_as_base : Error<
+ "base %0 is marked 'final'">;
+
+// C++0x attributes
+def err_repeat_attribute : Error<"'%0' attribute cannot be repeated">;
// C++0x [[final]]
def err_final_function_overridden : Error<
Modified: cfe/trunk/include/clang/Sema/Sema.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/Sema.h?rev=124039&r1=124038&r2=124039&view=diff
==============================================================================
--- cfe/trunk/include/clang/Sema/Sema.h (original)
+++ cfe/trunk/include/clang/Sema/Sema.h Sat Jan 22 11:51:53 2011
@@ -884,6 +884,7 @@
/// C++ record definition's base-specifiers clause and are starting its
/// member declarations.
void ActOnStartCXXMemberDeclarations(Scope *S, Decl *TagDecl,
+ ClassVirtSpecifiers &CVS,
SourceLocation LBraceLoc);
/// ActOnTagFinishDefinition - Invoked once we have finished parsing
Modified: cfe/trunk/lib/Parse/ParseDeclCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseDeclCXX.cpp?rev=124039&r1=124038&r2=124039&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParseDeclCXX.cpp (original)
+++ cfe/trunk/lib/Parse/ParseDeclCXX.cpp Sat Jan 22 11:51:53 2011
@@ -1772,7 +1772,8 @@
SourceLocation LBraceLoc = ConsumeBrace();
if (TagDecl)
- Actions.ActOnStartCXXMemberDeclarations(getCurScope(), TagDecl, LBraceLoc);
+ Actions.ActOnStartCXXMemberDeclarations(getCurScope(), TagDecl, CVS,
+ LBraceLoc);
// C++ 11p3: Members of a class defined with the keyword class are private
// by default. Members of a class defined with the keywords struct or union
Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=124039&r1=124038&r2=124039&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Sat Jan 22 11:51:53 2011
@@ -6423,6 +6423,7 @@
}
void Sema::ActOnStartCXXMemberDeclarations(Scope *S, Decl *TagD,
+ ClassVirtSpecifiers &CVS,
SourceLocation LBraceLoc) {
AdjustDeclIfTemplate(TagD);
CXXRecordDecl *Record = cast<CXXRecordDecl>(TagD);
@@ -6432,6 +6433,9 @@
if (!Record->getIdentifier())
return;
+ Record->setIsMarkedFinal(CVS.isFinalSpecified());
+ Record->setIsMarkedExplicit(CVS.isExplicitSpecified());
+
// C++ [class]p2:
// [...] The class-name is also inserted into the scope of the
// class itself; this is known as the injected-class-name. For
Modified: cfe/trunk/lib/Sema/SemaDeclCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclCXX.cpp?rev=124039&r1=124038&r2=124039&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclCXX.cpp Sat Jan 22 11:51:53 2011
@@ -521,6 +521,19 @@
CXXRecordDecl * CXXBaseDecl = cast<CXXRecordDecl>(BaseDecl);
assert(CXXBaseDecl && "Base type is not a C++ type");
+ // C++ [class.derived]p2:
+ // If a class is marked with the class-virt-specifier final and it appears
+ // as a base-type-specifier in a base-clause (10 class.derived), the program
+ // is ill-formed.
+ if (CXXBaseDecl->isMarkedFinal()) {
+ Diag(BaseLoc, diag::err_class_marked_final_used_as_base)
+ << CXXBaseDecl->getDeclName();
+ Diag(CXXBaseDecl->getLocation(), diag::note_previous_decl)
+ << CXXBaseDecl->getDeclName();
+ return 0;
+ }
+
+ // FIXME: Get rid of this.
// C++0x CWG Issue #817 indicates that [[final]] classes shouldn't be bases.
if (CXXBaseDecl->hasAttr<FinalAttr>()) {
Diag(BaseLoc, diag::err_final_base) << BaseType.getAsString();
Added: cfe/trunk/test/CXX/class/p2-0x.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/class/p2-0x.cpp?rev=124039&view=auto
==============================================================================
--- cfe/trunk/test/CXX/class/p2-0x.cpp (added)
+++ cfe/trunk/test/CXX/class/p2-0x.cpp Sat Jan 22 11:51:53 2011
@@ -0,0 +1,8 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s -std=c++0x
+namespace Test1 {
+
+class A final { }; // expected-note {{'A' declared here}}
+class B : A { }; // expected-error {{base 'A' is marked 'final'}}
+
+}
+
More information about the cfe-commits
mailing list