[cfe-commits] r116692 - in /cfe/trunk: include/clang/Basic/DiagnosticSemaKinds.td lib/Sema/SemaDecl.cpp test/CXX/dcl.dcl/dcl.attr/dcl.attr.override/ test/CXX/dcl.dcl/dcl.attr/dcl.attr.override/p1.cpp
Anders Carlsson
andersca at mac.com
Sun Oct 17 16:36:12 PDT 2010
Author: andersca
Date: Sun Oct 17 18:36:12 2010
New Revision: 116692
URL: http://llvm.org/viewvc/llvm-project?rev=116692&view=rev
Log:
Implement [dcl.attr.override]p2 and add tests for p1 and p2.
Added:
cfe/trunk/test/CXX/dcl.dcl/dcl.attr/dcl.attr.override/
cfe/trunk/test/CXX/dcl.dcl/dcl.attr/dcl.attr.override/p1.cpp
Modified:
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/lib/Sema/SemaDecl.cpp
Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=116692&r1=116691&r2=116692&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Sun Oct 17 18:36:12 2010
@@ -830,6 +830,10 @@
def err_final_base : Error<
"derivation from 'final' %0">;
+// C++0x [[override]]
+def err_override_function_not_overriding : Error<
+ "%0 marked 'override' but does not override any member functions">;
+
// C++0x scoped enumerations
def err_enum_invalid_underlying : Error<
"non-integral type %0 is an invalid underlying type">;
Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=116692&r1=116691&r2=116692&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Sun Oct 17 18:36:12 2010
@@ -3208,6 +3208,28 @@
}
}
+/// CheckClassMemberNameAttributes - Check for class member name checking
+/// attributes according to [dcl.attr.override]
+static void
+CheckClassMemberNameAttributes(Sema& SemaRef, const FunctionDecl *FD) {
+ const CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(FD);
+ if (!MD || !MD->isVirtual())
+ return;
+
+ bool HasOverrideAttr = MD->hasAttr<OverrideAttr>();
+ bool HasOverriddenMethods =
+ MD->begin_overridden_methods() != MD->end_overridden_methods();
+
+ /// C++ [dcl.attr.override]p2:
+ /// If a virtual member function f is marked override and does not override
+ /// a member function of a base class the program is ill-formed.
+ if (HasOverrideAttr && !HasOverriddenMethods) {
+ SemaRef.Diag(MD->getLocation(), diag::err_override_function_not_overriding)
+ << MD->getDeclName();
+ return;
+ }
+}
+
NamedDecl*
Sema::ActOnFunctionDeclarator(Scope* S, Declarator& D, DeclContext* DC,
QualType R, TypeSourceInfo *TInfo,
@@ -3855,6 +3877,8 @@
MarkUnusedFileScopedDecl(NewFD);
+ CheckClassMemberNameAttributes(*this, NewFD);
+
return NewFD;
}
@@ -6789,7 +6813,7 @@
// Flexible array member.
// Microsoft is more permissive regarding flexible array.
// It will accept flexible array in union and also
- // as the sole element of a struct/class.
+ // as the sole element of a struct/class.
if (getLangOptions().Microsoft) {
if (Record->isUnion())
Diag(FD->getLocation(), diag::ext_flexible_array_union)
Added: cfe/trunk/test/CXX/dcl.dcl/dcl.attr/dcl.attr.override/p1.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/dcl.dcl/dcl.attr/dcl.attr.override/p1.cpp?rev=116692&view=auto
==============================================================================
--- cfe/trunk/test/CXX/dcl.dcl/dcl.attr/dcl.attr.override/p1.cpp (added)
+++ cfe/trunk/test/CXX/dcl.dcl/dcl.attr/dcl.attr.override/p1.cpp Sun Oct 17 18:36:12 2010
@@ -0,0 +1,12 @@
+// RUN: %clang_cc1 -std=c++0x -fsyntax-only -verify %s
+
+struct A {
+ virtual void f();
+ virtual void h();
+};
+
+struct B : A {
+ [[override]] virtual void f();
+ [[override]] void g(); // expected-error {{'override' attribute only applies to virtual method types}}
+ [[override, override]] void h(); // expected-error {{'override' attribute cannot be repeated}}
+};
More information about the cfe-commits
mailing list