r214362 - Updating a comment related to the implementation of -Woverloaded-virtual, and adding a FIXME to a test case. (Drive-by removal of trailing whitespace in the test case as well.)

Aaron Ballman aaron at aaronballman.com
Wed Jul 30 16:50:53 PDT 2014


Author: aaronballman
Date: Wed Jul 30 18:50:53 2014
New Revision: 214362

URL: http://llvm.org/viewvc/llvm-project?rev=214362&view=rev
Log:
Updating a comment related to the implementation of -Woverloaded-virtual, and adding a FIXME to a test case. (Drive-by removal of trailing whitespace in the test case as well.)

No functional changes.

Modified:
    cfe/trunk/lib/Sema/SemaDeclCXX.cpp
    cfe/trunk/test/SemaCXX/warn-overloaded-virtual.cpp

Modified: cfe/trunk/lib/Sema/SemaDeclCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclCXX.cpp?rev=214362&r1=214361&r2=214362&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclCXX.cpp Wed Jul 30 18:50:53 2014
@@ -5945,7 +5945,14 @@ static bool FindHiddenVirtualMethod(cons
       if (!MD->isVirtual())
         continue;
       // If the method we are checking overrides a method from its base
-      // don't warn about the other overloaded methods.
+      // don't warn about the other overloaded methods. Clang deviates from GCC
+      // by only diagnosing overloads of inherited virtual functions that do not
+      // override any other virtual functions in the base. GCC's
+      // -Woverloaded-virtual diagnoses any derived function hiding a virtual
+      // function from a base class. These cases may be better served by a
+      // warning (not specific to virtual functions) on call sites when the call
+      // would select a different function from the base class, were it visible.
+      // See FIXME in test/SemaCXX/warn-overload-virtual.cpp for an example.
       if (!Data.S->IsOverload(Data.Method, MD, false))
         return true;
       // Collect the overload only if its hidden.

Modified: cfe/trunk/test/SemaCXX/warn-overloaded-virtual.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/warn-overloaded-virtual.cpp?rev=214362&r1=214361&r2=214362&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/warn-overloaded-virtual.cpp (original)
+++ cfe/trunk/test/SemaCXX/warn-overloaded-virtual.cpp Wed Jul 30 18:50:53 2014
@@ -48,8 +48,8 @@ struct Base {
 void Base::foo(int) { }
 
 struct Derived : public Base {
-  virtual void foo(int);   
-  void foo(int, int);   
+  virtual void foo(int);
+  void foo(int, int);
 };
 }
 
@@ -138,3 +138,21 @@ namespace {
     // expected-warning at -1{{hides overloaded virtual functions}}
   };
 }
+
+namespace {
+struct base {
+  void f(char) {}
+};
+
+struct derived : base {
+  void f(int) {}
+};
+
+void foo(derived &d) {
+  d.f('1'); // FIXME: this should warn about calling (anonymous namespace)::derived::f(int)
+            // instead of (anonymous namespace)::base::f(char).
+            // Note: this should be under a new diagnostic flag and eventually moved to a
+            // new test case since it's not strictly related to virtual functions.
+  d.f(12);  // This should not warn.
+}
+}





More information about the cfe-commits mailing list