[cfe-commits] r124031 - in /cfe/trunk: include/clang/Basic/DiagnosticSemaKinds.td lib/Sema/SemaDecl.cpp test/CXX/temp/temp.decls/temp.mem/p3.cpp
Anders Carlsson
andersca at mac.com
Sat Jan 22 06:43:56 PST 2011
Author: andersca
Date: Sat Jan 22 08:43:56 2011
New Revision: 124031
URL: http://llvm.org/viewvc/llvm-project?rev=124031&view=rev
Log:
A member function template cannot be virtual.
Added:
cfe/trunk/test/CXX/temp/temp.decls/temp.mem/p3.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=124031&r1=124030&r2=124031&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Sat Jan 22 08:43:56 2011
@@ -642,6 +642,8 @@
"'virtual' can only appear on non-static member functions">;
def err_virtual_out_of_class : Error<
"'virtual' can only be specified inside the class definition">;
+def err_virtual_member_function_template : Error<
+ "'virtual' can not be specified on member function templates">;
def err_static_overrides_virtual : Error<
"'static' member function %0 overrides a virtual function in a base class">;
def err_explicit_non_function : Error<
Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=124031&r1=124030&r2=124031&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Sat Jan 22 08:43:56 2011
@@ -3705,7 +3705,14 @@
diag::err_virtual_non_function);
} else if (!CurContext->isRecord()) {
// 'virtual' was specified outside of the class.
- Diag(D.getDeclSpec().getVirtualSpecLoc(), diag::err_virtual_out_of_class)
+ Diag(D.getDeclSpec().getVirtualSpecLoc(),
+ diag::err_virtual_out_of_class)
+ << FixItHint::CreateRemoval(D.getDeclSpec().getVirtualSpecLoc());
+ } else if (NewFD->getDescribedFunctionTemplate()) {
+ // C++ [temp.mem]p3:
+ // A member function template shall not be virtual.
+ Diag(D.getDeclSpec().getVirtualSpecLoc(),
+ diag::err_virtual_member_function_template)
<< FixItHint::CreateRemoval(D.getDeclSpec().getVirtualSpecLoc());
} else {
// Okay: Add virtual to the method.
Added: cfe/trunk/test/CXX/temp/temp.decls/temp.mem/p3.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/temp/temp.decls/temp.mem/p3.cpp?rev=124031&view=auto
==============================================================================
--- cfe/trunk/test/CXX/temp/temp.decls/temp.mem/p3.cpp (added)
+++ cfe/trunk/test/CXX/temp/temp.decls/temp.mem/p3.cpp Sat Jan 22 08:43:56 2011
@@ -0,0 +1,6 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+template <class T> struct AA {
+ template <class C> virtual void g(C); // expected-error{{'virtual' can not be specified on member function templates}}
+ virtual void f();
+};
More information about the cfe-commits
mailing list