summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStephan Bergmann <sbergman@redhat.com>2016-03-30 18:59:54 +0200
committerStephan Bergmann <sbergman@redhat.com>2016-03-30 18:59:54 +0200
commitd2f9f27774ec138c9f66c55f582a123d8ebd19ff (patch)
treeb984aa02aab3813d2a9c0ede9ad1e5d0fdf7fdb1
parent14060e76e33cfb305c1469fecf7db688bf8a8858 (diff)
loplugin:nullptr: Find some more cases in templates
Change-Id: I1f127d56e40b04f2b4df85c0afbcfd424d68a8cc
-rw-r--r--basegfx/source/inc/hommatrixtemplate.hxx2
-rw-r--r--compilerplugins/clang/nullptr.cxx72
-rw-r--r--include/comphelper/unique_disposing_ptr.hxx8
-rw-r--r--include/rtl/ref.hxx2
-rw-r--r--include/sfx2/controlwrapper.hxx6
-rw-r--r--include/sfx2/itemconnect.hxx4
-rw-r--r--include/vcl/scopedbitmapaccess.hxx2
-rw-r--r--lotuswordpro/source/filter/clone.hxx2
-rw-r--r--stoc/source/corereflection/lrucache.hxx6
-rw-r--r--stoc/source/security/lru_cache.h10
-rw-r--r--ucb/source/inc/regexpmap.hxx4
11 files changed, 85 insertions, 33 deletions
diff --git a/basegfx/source/inc/hommatrixtemplate.hxx b/basegfx/source/inc/hommatrixtemplate.hxx
index 77e2130e7359..c8cf4ae3a3d6 100644
--- a/basegfx/source/inc/hommatrixtemplate.hxx
+++ b/basegfx/source/inc/hommatrixtemplate.hxx
@@ -48,7 +48,7 @@ namespace basegfx
{
}
- explicit ImplMatLine(sal_uInt16 nRow, ImplMatLine< RowSize >* pToBeCopied = 0L)
+ explicit ImplMatLine(sal_uInt16 nRow, ImplMatLine< RowSize >* pToBeCopied = nullptr)
{
if(pToBeCopied)
{
diff --git a/compilerplugins/clang/nullptr.cxx b/compilerplugins/clang/nullptr.cxx
index 800343963b60..1e6311b1862b 100644
--- a/compilerplugins/clang/nullptr.cxx
+++ b/compilerplugins/clang/nullptr.cxx
@@ -51,6 +51,10 @@ public:
bool VisitCXXOperatorCallExpr(CXXOperatorCallExpr const * expr);
+ bool VisitParmVarDecl(ParmVarDecl const * decl);
+
+ bool TraverseConstructorInitializer(CXXCtorInitializer * init);
+
// bool shouldVisitTemplateInstantiations() const { return true; }
private:
@@ -60,6 +64,10 @@ private:
bool isMacroBodyExpansion(SourceLocation location) const;
+ void visitCXXCtorInitializer(CXXCtorInitializer const * init);
+
+ void handleZero(Expr const * expr);
+
void handleNull(
Expr const * expr, char const * castKind,
Expr::NullPointerConstantKind nullPointerKind);
@@ -142,12 +150,7 @@ bool Nullptr::VisitBinaryOperator(BinaryOperator const * expr) {
default:
return true;
}
- //TODO: detect NPCK_ZeroExpression where appropriate
- auto const lit = dyn_cast<IntegerLiteral>(e->IgnoreParenImpCasts());
- if (lit == nullptr || lit->getValue().getBoolValue()) {
- return true;
- }
- handleNull(e, nullptr, Expr::NPCK_ZeroLiteral);
+ handleZero(e);
return true;
}
@@ -173,15 +176,30 @@ bool Nullptr::VisitCXXOperatorCallExpr(CXXOperatorCallExpr const * expr) {
default:
return true;
}
- //TODO: detect NPCK_ZeroExpression where appropriate
- auto const lit = dyn_cast<IntegerLiteral>(e->IgnoreParenImpCasts());
- if (lit == nullptr || lit->getValue().getBoolValue()) {
+ handleZero(e);
+ return true;
+}
+
+bool Nullptr::VisitParmVarDecl(ParmVarDecl const * decl) {
+ if (ignoreLocation(decl)) {
+ return true;
+ }
+ if (!decl->getType()->isPointerType()) {
+ return true;
+ }
+ auto e = decl->getDefaultArg();
+ if (e == nullptr) {
return true;
}
- handleNull(e, nullptr, Expr::NPCK_ZeroLiteral);
+ handleZero(e);
return true;
}
+bool Nullptr::TraverseConstructorInitializer(CXXCtorInitializer * init) {
+ visitCXXCtorInitializer(init);
+ return RecursiveASTVisitor::TraverseConstructorInitializer(init);
+}
+
bool Nullptr::isInLokIncludeFile(SourceLocation spellingLocation) const {
return compiler.getSourceManager().getFilename(spellingLocation)
.startswith(SRCDIR "/include/LibreOfficeKit/");
@@ -204,6 +222,40 @@ bool Nullptr::isMacroBodyExpansion(SourceLocation location) const {
#endif
}
+void Nullptr::visitCXXCtorInitializer(CXXCtorInitializer const * init) {
+ if (!init->isWritten()) {
+ return;
+ }
+ auto e = init->getInit();
+ if (ignoreLocation(e)) {
+ return;
+ }
+ auto d = init->getAnyMember();
+ if (d == nullptr || !d->getType()->isPointerType()) {
+ return;
+ }
+ if (auto e2 = dyn_cast<ParenListExpr>(e)) {
+ if (e2->getNumExprs() != 1) {
+ return;
+ }
+ e = e2->getExpr(0);
+ } else if (auto e2 = dyn_cast<InitListExpr>(e)) {
+ if (e2->getNumInits() != 1) {
+ return;
+ }
+ e = e2->getInit(0);
+ }
+ handleZero(e);
+}
+
+void Nullptr::handleZero(Expr const * expr) {
+ //TODO: detect NPCK_ZeroExpression where appropriate
+ auto const lit = dyn_cast<IntegerLiteral>(expr->IgnoreParenImpCasts());
+ if (lit != nullptr && !lit->getValue().getBoolValue()) {
+ handleNull(expr, nullptr, Expr::NPCK_ZeroLiteral);
+ }
+}
+
void Nullptr::handleNull(
Expr const * expr, char const * castKind,
Expr::NullPointerConstantKind nullPointerKind)
diff --git a/include/comphelper/unique_disposing_ptr.hxx b/include/comphelper/unique_disposing_ptr.hxx
index 1ed7c1b6eeb5..0f120b179392 100644
--- a/include/comphelper/unique_disposing_ptr.hxx
+++ b/include/comphelper/unique_disposing_ptr.hxx
@@ -30,13 +30,13 @@ private:
unique_disposing_ptr(const unique_disposing_ptr&) = delete;
unique_disposing_ptr& operator=(const unique_disposing_ptr&) = delete;
public:
- unique_disposing_ptr( const css::uno::Reference< css::lang::XComponent > &rComponent, T * p = 0 )
+ unique_disposing_ptr( const css::uno::Reference< css::lang::XComponent > &rComponent, T * p = nullptr )
: m_xItem(p)
{
m_xTerminateListener = new TerminateListener(rComponent, *this);
}
- virtual void reset(T * p = 0)
+ virtual void reset(T * p = nullptr)
{
m_xItem.reset(p);
}
@@ -141,12 +141,12 @@ template<class T> class unique_disposing_solar_mutex_reset_ptr
: public unique_disposing_ptr<T>
{
public:
- unique_disposing_solar_mutex_reset_ptr( const css::uno::Reference< css::lang::XComponent > &rComponent, T * p = 0 )
+ unique_disposing_solar_mutex_reset_ptr( const css::uno::Reference< css::lang::XComponent > &rComponent, T * p = nullptr )
: unique_disposing_ptr<T>(rComponent, p)
{
}
- virtual void reset(T * p = 0) override
+ virtual void reset(T * p = nullptr) override
{
SolarMutexGuard aGuard;
unique_disposing_ptr<T>::reset(p);
diff --git a/include/rtl/ref.hxx b/include/rtl/ref.hxx
index ea219cdae77b..685b7f2d2a2c 100644
--- a/include/rtl/ref.hxx
+++ b/include/rtl/ref.hxx
@@ -43,7 +43,7 @@ public:
/** Constructor...
*/
inline Reference()
- : m_pBody (0)
+ : m_pBody (NULL)
{}
diff --git a/include/sfx2/controlwrapper.hxx b/include/sfx2/controlwrapper.hxx
index d56e7f26aba8..33db87efaad0 100644
--- a/include/sfx2/controlwrapper.hxx
+++ b/include/sfx2/controlwrapper.hxx
@@ -79,7 +79,7 @@ public:
is used (simply casting between list position and values). If the map
exists, it *MUST* be terminated by an entry containing the special
"not found" list position. */
- inline explicit PosValueMapper( PosT nNFPos, const MapEntryType* pMap = 0 ) :
+ inline explicit PosValueMapper( PosT nNFPos, const MapEntryType* pMap = nullptr ) :
mpMap( pMap ), mnNFPos( nNFPos ) {}
/** Returns the value at the specified list position.
@@ -325,7 +325,7 @@ public:
/** @param pMap Optional list position <-> value map.
See PosValueMapper documentation for details. */
- inline explicit ListBoxWrapper( ListBox& rListBox, const MapEntryType* pMap = 0 ) :
+ inline explicit ListBoxWrapper( ListBox& rListBox, const MapEntryType* pMap = nullptr ) :
SingleControlWrapper< ListBox, ValueT >( rListBox ), MapperType( WRAPPER_LISTBOX_ENTRY_NOTFOUND, pMap ) {}
virtual bool IsControlDontKnow() const SAL_OVERRIDE
@@ -358,7 +358,7 @@ public:
/** @param pMap Optional position <-> value map.
See PosValueMapper documentation for details. */
- inline explicit ValueSetWrapper( ValueSet& rValueSet, const MapEntryType* pMap = 0 ) :
+ inline explicit ValueSetWrapper( ValueSet& rValueSet, const MapEntryType* pMap = nullptr ) :
SingleControlWrapper< ValueSet, ValueT >( rValueSet ), MapperType( WRAPPER_VALUESET_ITEM_NOTFOUND, pMap ) {}
virtual bool IsControlDontKnow() const SAL_OVERRIDE
diff --git a/include/sfx2/itemconnect.hxx b/include/sfx2/itemconnect.hxx
index 95cc97f9f229..bfe9b253e926 100644
--- a/include/sfx2/itemconnect.hxx
+++ b/include/sfx2/itemconnect.hxx
@@ -354,7 +354,7 @@ public:
typedef typename ListBoxWrapperType::MapEntryType MapEntryType;
explicit ListBoxConnection( sal_uInt16 nSlot, ListBox& rListBox,
- const MapEntryType* pMap = 0, ItemConnFlags nFlags = ITEMCONN_DEFAULT );
+ const MapEntryType* pMap = nullptr, ItemConnFlags nFlags = ITEMCONN_DEFAULT );
};
@@ -379,7 +379,7 @@ public:
typedef typename ValueSetWrapperType::MapEntryType MapEntryType;
explicit ValueSetConnection( sal_uInt16 nSlot, ValueSet& rValueSet,
- const MapEntryType* pMap = 0, ItemConnFlags nFlags = ITEMCONN_DEFAULT );
+ const MapEntryType* pMap = nullptr, ItemConnFlags nFlags = ITEMCONN_DEFAULT );
};
diff --git a/include/vcl/scopedbitmapaccess.hxx b/include/vcl/scopedbitmapaccess.hxx
index ccec9c9d2600..bb5c8bf61c17 100644
--- a/include/vcl/scopedbitmapaccess.hxx
+++ b/include/vcl/scopedbitmapaccess.hxx
@@ -50,7 +50,7 @@ template < class Access, class Bitmap, Access* (Bitmap::* Acquire)() > class Sco
public:
explicit ScopedBitmapAccess( Bitmap& rBitmap ) :
- mpAccess( 0 ),
+ mpAccess( nullptr ),
mrBitmap( rBitmap )
{
mpAccess = (mrBitmap.*Acquire)();
diff --git a/lotuswordpro/source/filter/clone.hxx b/lotuswordpro/source/filter/clone.hxx
index bc2f7fb71e84..a6747c005a86 100644
--- a/lotuswordpro/source/filter/clone.hxx
+++ b/lotuswordpro/source/filter/clone.hxx
@@ -23,7 +23,7 @@ struct has_clone
typedef struct { char a[2]; } no;
template<typename U>
- static yes& check_sig(U*, test<U* (U::*)() const, &U::clone>* = 0);
+ static yes& check_sig(U*, test<U* (U::*)() const, &U::clone>* = nullptr);
template<typename U>
static no& check_sig(...);
diff --git a/stoc/source/corereflection/lrucache.hxx b/stoc/source/corereflection/lrucache.hxx
index 3bfb878b72ae..13f4803ca085 100644
--- a/stoc/source/corereflection/lrucache.hxx
+++ b/stoc/source/corereflection/lrucache.hxx
@@ -90,9 +90,9 @@ inline LRU_Cache< t_Key, t_Val, t_KeyHash >::LRU_Cache( sal_Int32 nCachedElement
#else
: _nCachedElements( nCachedElements )
#endif
- , _pBlock( 0 )
- , _pHead( 0 )
- , _pTail( 0 )
+ , _pBlock( nullptr )
+ , _pHead( nullptr )
+ , _pTail( nullptr )
{
if (_nCachedElements > 0)
{
diff --git a/stoc/source/security/lru_cache.h b/stoc/source/security/lru_cache.h
index 11a333b161bc..b2c384706a86 100644
--- a/stoc/source/security/lru_cache.h
+++ b/stoc/source/security/lru_cache.h
@@ -115,8 +115,8 @@ template< typename t_key, typename t_val, typename t_hashKey, typename t_equalKe
inline lru_cache< t_key, t_val, t_hashKey, t_equalKey >::lru_cache(
::std::size_t size )
: m_size( 0 )
- , m_block( 0 )
- , m_tail( 0 )
+ , m_block( nullptr )
+ , m_tail( nullptr )
{
setSize( size );
}
@@ -124,9 +124,9 @@ inline lru_cache< t_key, t_val, t_hashKey, t_equalKey >::lru_cache(
template< typename t_key, typename t_val, typename t_hashKey, typename t_equalKey >
inline lru_cache< t_key, t_val, t_hashKey, t_equalKey >::lru_cache()
: m_size( 0 )
- , m_block( 0 )
- , m_head( 0 )
- , m_tail( 0 )
+ , m_block( nullptr )
+ , m_head( nullptr )
+ , m_tail( nullptr )
{
}
diff --git a/ucb/source/inc/regexpmap.hxx b/ucb/source/inc/regexpmap.hxx
index ab714ed6f793..45a64fdb68f6 100644
--- a/ucb/source/inc/regexpmap.hxx
+++ b/ucb/source/inc/regexpmap.hxx
@@ -75,7 +75,7 @@ struct RegexpMapImpl
List< Val > m_aList[Regexp::KIND_DOMAIN + 1];
Entry< Val > * m_pDefault;
- RegexpMapImpl(): m_pDefault(0) {}
+ RegexpMapImpl(): m_pDefault(nullptr) {}
~RegexpMapImpl() { delete m_pDefault; }
};
@@ -126,7 +126,7 @@ private:
template< typename Val >
inline RegexpMapIterImpl< Val >::RegexpMapIterImpl():
m_aEntry(rtl::OUString(), 0),
- m_pMap(0),
+ m_pMap(nullptr),
m_nList(-1),
m_bEntrySet(false)
{}