Further restrict issuance of 'override' warning if method
authorFariborz Jahanian <fjahanian@apple.com>
Mon, 3 Nov 2014 19:46:18 +0000 (19:46 +0000)
committerFariborz Jahanian <fjahanian@apple.com>
Mon, 3 Nov 2014 19:46:18 +0000 (19:46 +0000)
is argument to a macro which is defined in system header.

llvm-svn: 221172

clang/lib/Sema/SemaDeclCXX.cpp
clang/test/SemaCXX/Inputs/override-system-header.h
clang/test/SemaCXX/override-in-system-header.cpp

index 0fae8c8..c115745 100644 (file)
@@ -1905,12 +1905,14 @@ void Sema::DiagnoseAbsenceOfOverrideControl(NamedDecl *D) {
       isa<CXXDestructorDecl>(MD))
     return;
 
-  if (MD->getLocation().isMacroID()) {
-    SourceLocation MacroLoc = getSourceManager().getSpellingLoc(MD->getLocation());
-    if (getSourceManager().isInSystemHeader(MacroLoc))
+  SourceLocation Loc = MD->getLocation();
+  SourceLocation SpellingLoc = Loc;
+  if (getSourceManager().isMacroArgExpansion(Loc))
+    SpellingLoc = getSourceManager().getImmediateExpansionRange(Loc).first;
+  SpellingLoc = getSourceManager().getSpellingLoc(SpellingLoc);
+  if (SpellingLoc.isValid() && getSourceManager().isInSystemHeader(SpellingLoc))
       return;
-  }
-  
+    
   if (MD->size_overridden_methods() > 0) {
     Diag(MD->getLocation(), diag::warn_function_marked_not_override_overriding)
       << MD->getDeclName();
index 9a1bde5..9831ab7 100644 (file)
@@ -1,3 +1,6 @@
 // override-system-header.h to test out 'override' warning.
 // rdar://18295240
 #define END_COM_MAP virtual unsigned AddRef(void) = 0;
+
+#define STDMETHOD(method)        virtual void method
+#define IFACEMETHOD(method)         STDMETHOD(method)
index 88c53e4..689585e 100644 (file)
@@ -8,10 +8,12 @@ struct A
 {
   virtual void x();
   END_COM_MAP;
+  IFACEMETHOD(Initialize)();
 };
  
 struct B : A
 {
   virtual void x() override;
   END_COM_MAP;
+  IFACEMETHOD(Initialize)();
 };