Skip to content

Commit

Permalink
Brute force silence clang analyzer false positives
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Dec 15, 2022
1 parent c41b7f1 commit 5c1e312
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/core/expression/qgsexpressionutils.cpp
Expand Up @@ -61,6 +61,12 @@ QgsMapLayer *QgsExpressionUtils::getMapLayerPrivate( const QVariant &value, cons
{
// First check if we already received a layer pointer
QPointer< QgsMapLayer > ml = value.value< QgsWeakMapLayerPointer >().data();

// clang analyzer gets this function absolutely 100% wrong
#ifdef __clang_analyzer__
( void )context;
#else

if ( !ml )
{
ml = value.value< QgsMapLayer * >();
Expand All @@ -82,6 +88,7 @@ QgsMapLayer *QgsExpressionUtils::getMapLayerPrivate( const QVariant &value, cons
const QList< QgsMapLayerStore * > stores = context->layerStores();
for ( QgsMapLayerStore *store : stores )
{

QPointer< QgsMapLayerStore > storePointer( store );
auto findLayerInStoreFunction = [ storePointer, &ml, identifier ]
{
Expand Down Expand Up @@ -123,7 +130,6 @@ QgsMapLayer *QgsExpressionUtils::getMapLayerPrivate( const QVariant &value, cons
ml = project->mapLayersByName( identifier ).value( 0 );
};

#ifndef __clang_analyzer__
if ( QThread::currentThread() == qApp->thread() )
getMapLayerFromProjectInstance();
else
Expand All @@ -136,6 +142,10 @@ QgsMapLayer *QgsExpressionUtils::getMapLayerPrivate( const QVariant &value, cons
void QgsExpressionUtils::executeLambdaForMapLayer( const QVariant &value, const QgsExpressionContext *context, QgsExpression *expression, const std::function<void ( QgsMapLayer * )> &function, bool &foundLayer )
{
foundLayer = false;

// clang analyzer gets this function absolutely 100% wrong
#ifndef __clang_analyzer__

// First check if we already received a layer pointer
QPointer< QgsMapLayer > ml = value.value< QgsWeakMapLayerPointer >().data();
if ( !ml )
Expand Down Expand Up @@ -267,6 +277,7 @@ void QgsExpressionUtils::executeLambdaForMapLayer( const QVariant &value, const
else
QMetaObject::invokeMethod( QgsProject::instance(), getMapLayerFromProjectInstance, Qt::BlockingQueuedConnection );
}
#endif
}

QVariant QgsExpressionUtils::runMapLayerFunctionThreadSafe( const QVariant &value, const QgsExpressionContext *context, QgsExpression *expression, const std::function<QVariant( QgsMapLayer * )> &function, bool &foundLayer )
Expand Down

0 comments on commit 5c1e312

Please sign in to comment.