[Libreoffice-commits] core.git: 2 commits - basctl/source compilerplugins/clang include/tools

Noel Grandin noel at peralex.com
Fri Nov 20 01:49:15 PST 2015


 basctl/source/basicide/basicbox.cxx    |    2 -
 basctl/source/basicide/bastypes.cxx    |    4 --
 basctl/source/dlged/managelang.cxx     |    2 -
 basctl/source/inc/bastypes.hxx         |    3 --
 basctl/source/inc/managelang.hxx       |    5 ---
 compilerplugins/clang/unusedfields.cxx |   45 +++++++++++++++++++++++++++++++--
 include/tools/weakbase.h               |    2 -
 7 files changed, 49 insertions(+), 14 deletions(-)

New commits:
commit ad278c2b3a83f2fb2896aa048820cab93fddba69
Author: Noel Grandin <noel at peralex.com>
Date:   Fri Nov 20 11:48:33 2015 +0200

    loplugin:unusedfields in basctl
    
    and improve the plugin to search for only WARN_UNUSED and fundamental
    types
    
    Change-Id: Ic06207758e28d44d64d76d8119fd76b5b098bb05

diff --git a/basctl/source/basicide/basicbox.cxx b/basctl/source/basicide/basicbox.cxx
index f4922b5..78518d1 100644
--- a/basctl/source/basicide/basicbox.cxx
+++ b/basctl/source/basicide/basicbox.cxx
@@ -418,7 +418,7 @@ void LanguageBox::FillBox()
                 sLanguage += m_sDefaultLanguageStr;
             }
             sal_Int32 nPos = InsertEntry( sLanguage );
-            SetEntryData( nPos, new LanguageEntry( sLanguage, pLocale[i], bIsDefault ) );
+            SetEntryData( nPos, new LanguageEntry( pLocale[i], bIsDefault ) );
 
             if ( bIsCurrent )
                 nSelPos = nPos;
diff --git a/basctl/source/basicide/bastypes.cxx b/basctl/source/basicide/bastypes.cxx
index 30f83fa..4d0da3c 100644
--- a/basctl/source/basicide/bastypes.cxx
+++ b/basctl/source/basicide/bastypes.cxx
@@ -732,7 +732,7 @@ void LibInfos::InsertInfo (
 {
     Key aKey(rDocument, rLibName);
     m_aMap.erase(aKey);
-    m_aMap.insert(Map::value_type(aKey, Item(rDocument, rLibName, rCurrentName, eCurrentType)));
+    m_aMap.insert(Map::value_type(aKey, Item(rDocument, rCurrentName, eCurrentType)));
 }
 
 void LibInfos::RemoveInfoFor (ScriptDocument const& rDocument)
@@ -772,12 +772,10 @@ size_t LibInfos::Key::Hash::operator () (Key const& rKey) const
 
 LibInfos::Item::Item (
     ScriptDocument const& rDocument,
-    OUString const& rLibName,
     OUString const& rCurrentName,
     ItemType eCurrentType
 ) :
     m_aDocument(rDocument),
-    m_aLibName(rLibName),
     m_aCurrentName(rCurrentName),
     m_eCurrentType(eCurrentType)
 { }
diff --git a/basctl/source/dlged/managelang.cxx b/basctl/source/dlged/managelang.cxx
index 3864f83..56c0e8c 100644
--- a/basctl/source/dlged/managelang.cxx
+++ b/basctl/source/dlged/managelang.cxx
@@ -126,7 +126,7 @@ void ManageLanguageDialog::FillLanguageBox()
                 sLanguage += " " + m_sDefLangStr;
             }
             const sal_Int32 nPos = m_pLanguageLB->InsertEntry( sLanguage );
-            m_pLanguageLB->SetEntryData( nPos, new LanguageEntry( sLanguage, pLocale[i], bIsDefault ) );
+            m_pLanguageLB->SetEntryData( nPos, new LanguageEntry( pLocale[i], bIsDefault ) );
         }
     }
     else
diff --git a/basctl/source/inc/bastypes.hxx b/basctl/source/inc/bastypes.hxx
index 52a49b2..d09a0cc 100644
--- a/basctl/source/inc/bastypes.hxx
+++ b/basctl/source/inc/bastypes.hxx
@@ -273,12 +273,11 @@ public:
     {
     private:
         ScriptDocument  m_aDocument;
-        OUString        m_aLibName;
         OUString        m_aCurrentName;
         ItemType        m_eCurrentType;
 
     public:
-        Item (ScriptDocument const&, OUString const& rLibName, OUString const& rCurrentName, ItemType eCurrentType);
+        Item (ScriptDocument const&, OUString const& rCurrentName, ItemType eCurrentType);
         ~Item ();
         const OUString& GetCurrentName()        const { return m_aCurrentName; }
         ItemType        GetCurrentType()        const { return m_eCurrentType; }
diff --git a/basctl/source/inc/managelang.hxx b/basctl/source/inc/managelang.hxx
index a9a8eca..14bf403 100644
--- a/basctl/source/inc/managelang.hxx
+++ b/basctl/source/inc/managelang.hxx
@@ -34,14 +34,11 @@ class LocalizationMgr;
 
 struct LanguageEntry
 {
-    OUString                        m_sLanguage;
     css::lang::Locale               m_aLocale;
     bool                            m_bIsDefault;
 
-    LanguageEntry( const OUString& _rLanguage,
-                   const css::lang::Locale& _rLocale,
+    LanguageEntry( const css::lang::Locale& _rLocale,
                    bool _bIsDefault ) :
-        m_sLanguage( _rLanguage ),
         m_aLocale( _rLocale ),
         m_bIsDefault( _bIsDefault ) {}
 };
diff --git a/compilerplugins/clang/unusedfields.cxx b/compilerplugins/clang/unusedfields.cxx
index 95bce5e..d002356 100644
--- a/compilerplugins/clang/unusedfields.cxx
+++ b/compilerplugins/clang/unusedfields.cxx
@@ -170,8 +170,49 @@ bool UnusedFields::VisitFieldDecl( const FieldDecl* fieldDecl )
 {
     fieldDecl = fieldDecl->getCanonicalDecl();
 
-    if( !ignoreLocation( fieldDecl ))
-        definitionSet.insert(niceName(fieldDecl));
+    if( ignoreLocation( fieldDecl ))
+        return true;
+
+    QualType type = fieldDecl->getType();
+    // unwrap array types
+    while (type->isArrayType())
+        type = type->getAsArrayTypeUnsafe()->getElementType();
+
+    if( CXXRecordDecl* recordDecl = type->getAsCXXRecordDecl() )
+    {
+        bool warn_unused = false;
+        if( recordDecl->hasAttrs())
+        {
+                // Clang currently has no support for custom attributes, but
+                // the annotate attribute comes close, so check for __attribute__((annotate("lo_warn_unused")))
+                for( specific_attr_iterator<AnnotateAttr> i = recordDecl->specific_attr_begin<AnnotateAttr>(),
+                 e = recordDecl->specific_attr_end<AnnotateAttr>();
+                 i != e;
+                 ++i )
+                {
+                    if( (*i)->getAnnotation() == "lo_warn_unused" )
+                    {
+                        warn_unused = true;
+                        break;
+                    }
+                }
+        }
+        if( !warn_unused )
+        {
+            string n = recordDecl->getQualifiedNameAsString();
+            if( n == "rtl::OUString" )
+                warn_unused = true;
+            // Check some common non-LO types.
+            if( n == "std::string" || n == "std::basic_string"
+                || n == "std::list" || n == "std::__debug::list"
+                || n == "std::vector" || n == "std::__debug::vector" )
+                warn_unused = true;
+        }
+        if (!warn_unused)
+            return true;
+    }
+
+    definitionSet.insert(niceName(fieldDecl));
     return true;
 }
 
commit 6f5c6cf4902c3a4a49567e95ff26260632a8f4e9
Author: Noel Grandin <noel at peralex.com>
Date:   Fri Nov 20 11:03:52 2015 +0200

    mark WeakReference with SAL_WARN_UNUSED
    
    Change-Id: I9d56cdecba8066058a0c6f128720534fcf6f6e34

diff --git a/include/tools/weakbase.h b/include/tools/weakbase.h
index 366358f..cd1ab64 100644
--- a/include/tools/weakbase.h
+++ b/include/tools/weakbase.h
@@ -68,7 +68,7 @@ struct WeakConnection
 
 /** template implementation to hold a weak reference to an instance of type reference_type */
 template <class reference_type>
-class WeakReference
+class SAL_WARN_UNUSED WeakReference
 {
 public:
     /** constructs an empty reference */


More information about the Libreoffice-commits mailing list