]> granicus.if.org Git - clang/commitdiff
A member function template cannot be virtual.
authorAnders Carlsson <andersca@mac.com>
Sat, 22 Jan 2011 14:43:56 +0000 (14:43 +0000)
committerAnders Carlsson <andersca@mac.com>
Sat, 22 Jan 2011 14:43:56 +0000 (14:43 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@124031 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Basic/DiagnosticSemaKinds.td
lib/Sema/SemaDecl.cpp
test/CXX/temp/temp.decls/temp.mem/p3.cpp [new file with mode: 0644]

index e4b4685552a34d8198bca36de2070090d7de5d25..0743d161248b83e023b2d3bd42e19c6b59e16cd2 100644 (file)
@@ -642,6 +642,8 @@ def err_virtual_non_function : Error<
   "'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<
index be6d60e65741fe95f6c89040750d09e40ffb4b6a..a266b60ac386fdcb85091237aa8f92040e2a97d7 100644 (file)
@@ -3705,7 +3705,14 @@ Sema::ActOnFunctionDeclarator(Scope* S, Declarator& D, DeclContext* DC,
              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.
diff --git a/test/CXX/temp/temp.decls/temp.mem/p3.cpp b/test/CXX/temp/temp.decls/temp.mem/p3.cpp
new file mode 100644 (file)
index 0000000..0eb747b
--- /dev/null
@@ -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();
+};