Skip to content
Permalink
Browse files
Change prototypes of extern functions of C++ plugins...
... to fix the -Wreturn-type-c-linkage warnings.

The methods that returned a QString now return a const QString*.

This is a breakage for out-of-tree native plugins.
  • Loading branch information
rouault authored and nyalldawson committed Jul 22, 2021
1 parent 276d198 commit b3c5cf8d5fc1fdc289f1449df548acf9268140c6
@@ -620,7 +620,7 @@ if (PEDANTIC)
# add_definitions( -fstrict-aliasing -Wstrict-aliasing=1 -Wredundant-decls )

if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-return-type-c-linkage -Woverloaded-virtual -Wimplicit-fallthrough")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wreturn-type-c-linkage -Woverloaded-virtual -Wimplicit-fallthrough")
endif()

# add any extra CXXFLAGS flags set by user. can be -D CXX_EXTRA_FLAGS or environment variable
@@ -441,55 +441,55 @@ void QgsPluginManager::getCppPluginsMetadata()
// show the values (or lack of) for each function
if ( pName )
{
QgsDebugMsgLevel( "Plugin name: " + pName(), 2 );
QgsDebugMsgLevel( "Plugin name: " + *pName(), 2 );
}
else
{
QgsDebugMsgLevel( QStringLiteral( "Plugin name not returned when queried" ), 2 );
}
if ( pDesc )
{
QgsDebugMsgLevel( "Plugin description: " + pDesc(), 2 );
QgsDebugMsgLevel( "Plugin description: " + *pDesc(), 2 );
}
else
{
QgsDebugMsgLevel( QStringLiteral( "Plugin description not returned when queried" ), 2 );
}
if ( pCat )
{
QgsDebugMsgLevel( "Plugin category: " + pCat(), 2 );
QgsDebugMsgLevel( "Plugin category: " + *pCat(), 2 );
}
else
{
QgsDebugMsgLevel( QStringLiteral( "Plugin category not returned when queried" ), 2 );
}
if ( pVersion )
{
QgsDebugMsgLevel( "Plugin version: " + pVersion(), 2 );
QgsDebugMsgLevel( "Plugin version: " + *pVersion(), 2 );
}
else
{
QgsDebugMsgLevel( QStringLiteral( "Plugin version not returned when queried" ), 2 );
}
if ( pIcon )
{
QgsDebugMsgLevel( "Plugin icon: " + pIcon(), 2 );
QgsDebugMsgLevel( "Plugin icon: " + *pIcon(), 2 );
}
else
{
QgsDebugMsgLevel( QStringLiteral( "Plugin icon not returned when queried" ), 2 );
}
if ( pCreateDate )
{
QgsDebugMsgLevel( "Plugin create date: " + pCreateDate(), 2 );
QgsDebugMsgLevel( "Plugin create date: " + *pCreateDate(), 2 );
}
else
{
QgsDebugMsgLevel( QStringLiteral( "Plugin create date not returned when queried" ), 2 );
}
if ( pUpdateDate )
{
QgsDebugMsgLevel( "Plugin update date: " + pUpdateDate(), 2 );
QgsDebugMsgLevel( "Plugin update date: " + *pUpdateDate(), 2 );
}
else
{
@@ -508,19 +508,19 @@ void QgsPluginManager::getCppPluginsMetadata()

QMap<QString, QString> metadata;
metadata[QStringLiteral( "id" )] = baseName;
metadata[QStringLiteral( "name" )] = pName();
metadata[QStringLiteral( "description" )] = pDesc();
metadata[QStringLiteral( "category" )] = ( pCat ? pCat() : tr( "Plugins" ) );
metadata[QStringLiteral( "version_installed" )] = pVersion();
metadata[QStringLiteral( "icon" )] = ( pIcon ? pIcon() : QString() );
metadata[QStringLiteral( "name" )] = *pName();
metadata[QStringLiteral( "description" )] = *pDesc();
metadata[QStringLiteral( "category" )] = ( pCat ? *pCat() : tr( "Plugins" ) );
metadata[QStringLiteral( "version_installed" )] = *pVersion();
metadata[QStringLiteral( "icon" )] = ( pIcon ? *pIcon() : QString() );
metadata[QStringLiteral( "library" )] = myLib->fileName();
metadata[QStringLiteral( "pythonic" )] = QStringLiteral( "false" );
metadata[QStringLiteral( "installed" )] = QStringLiteral( "true" );
metadata[QStringLiteral( "readonly" )] = QStringLiteral( "true" );
metadata[QStringLiteral( "status" )] = QStringLiteral( "orphan" );
metadata[QStringLiteral( "experimental" )] = ( pExperimental ? pExperimental() : QString() );
metadata[QStringLiteral( "create_date" )] = ( pCreateDate ? pCreateDate() : QString() );
metadata[QStringLiteral( "update_date" )] = ( pUpdateDate ? pUpdateDate() : QString() );
metadata[QStringLiteral( "experimental" )] = ( pExperimental ? *pExperimental() : QString() );
metadata[QStringLiteral( "create_date" )] = ( pCreateDate ? *pCreateDate() : QString() );
metadata[QStringLiteral( "update_date" )] = ( pUpdateDate ? *pUpdateDate() : QString() );
mPlugins.insert( baseName, metadata );

delete myLib;
@@ -41,9 +41,9 @@

/* typedefs for plugins */
typedef QgisPlugin *create_ui( QgisInterface *qI );
typedef QString name_t();
typedef QString description_t();
typedef QString category_t();
typedef const QString *name_t();
typedef const QString *description_t();
typedef const QString *category_t();
typedef int type_t();


@@ -372,10 +372,10 @@ void QgsPluginRegistry::loadCppPlugin( const QString &fullPathName )
{
pl->initGui();
// add it to the plugin registry
addPlugin( baseName, QgsPluginMetadata( myLib.fileName(), pName(), pl ) );
addPlugin( baseName, QgsPluginMetadata( myLib.fileName(), *pName(), pl ) );
//add it to the qsettings file [ts]
settings.setValue( "/Plugins/" + baseName, true );
QgsMessageLog::logMessage( QObject::tr( "Loaded %1 (Path: %2)" ).arg( pName(), myLib.fileName() ), QObject::tr( "Plugins" ), Qgis::MessageLevel::Info );
QgsMessageLog::logMessage( QObject::tr( "Loaded %1 (Path: %2)" ).arg( *pName(), myLib.fileName() ), QObject::tr( "Plugins" ), Qgis::MessageLevel::Info );

QObject *o = dynamic_cast<QObject *>( pl );
if ( o )
@@ -1252,10 +1252,6 @@ typedef unsigned long long qgssize;
#ifndef QGISEXTERN
#ifdef Q_OS_WIN
# define QGISEXTERN extern "C" __declspec( dllexport )
# ifdef _MSC_VER
// do not warn about C bindings returning QString
# pragma warning(disable:4190)
# endif
#else
# if defined(__GNUC__) || defined(__clang__)
# define QGISEXTERN extern "C" __attribute__ ((visibility ("default")))
@@ -68,21 +68,21 @@ QGISEXTERN QgisPlugin *classFactory( QgisInterface *qgisInterfacePointer )
}
// Return the name of the plugin - note that we do not user class members as
// the class may not yet be insantiated when this method is called.
QGISEXTERN QString name()
QGISEXTERN const QString *name()
{
return sName;
return &sName;
}

// Return the description
QGISEXTERN QString description()
QGISEXTERN const QString *description()
{
return sDescription;
return &sDescription;
}

// Return the category
QGISEXTERN QString category()
QGISEXTERN const QString *category()
{
return sCategory;
return &sCategory;
}

// Return the type (either UI or MapLayer plugin)
@@ -92,14 +92,14 @@ QGISEXTERN int type()
}

// Return the version number for the plugin
QGISEXTERN QString version()
QGISEXTERN const QString *version()
{
return sPluginVersion;
return &sPluginVersion;
}

QGISEXTERN QString icon()
QGISEXTERN const QString *icon()
{
return sPluginIcon;
return &sPluginIcon;
}

// Delete ourself
@@ -704,21 +704,21 @@ QGISEXTERN QgisPlugin *classFactory( QgisInterface *qgisInterfacePointer )

// Return the name of the plugin - note that we do not user class members as
// the class may not yet be insantiated when this method is called.
QGISEXTERN QString name()
QGISEXTERN const QString *name()
{
return name_;
return &name_;
}

// Return the description
QGISEXTERN QString description()
QGISEXTERN const QString *description()
{
return description_;
return &description_;
}

// Return the category
QGISEXTERN QString category()
QGISEXTERN const QString *category()
{
return category_;
return &category_;
}

// Return the type (either UI or MapLayer plugin)
@@ -728,14 +728,14 @@ QGISEXTERN int type()
}

// Return the version number for the plugin
QGISEXTERN QString version()
QGISEXTERN const QString *version()
{
return version_;
return &version_;
}

QGISEXTERN QString icon()
QGISEXTERN const QString *icon()
{
return icon_;
return &icon_;
}

// Delete ourself
@@ -907,21 +907,21 @@ QGISEXTERN QgisPlugin *classFactory( QgisInterface *qgisInterfacePointer )

// Return the name of the plugin - note that we do not user class members as
// the class may not yet be insantiated when this method is called.
QGISEXTERN QString name()
QGISEXTERN const QString *name()
{
return pluginName;
return &pluginName;
}

// Return the description
QGISEXTERN QString description()
QGISEXTERN const QString *description()
{
return pluginDescription;
return &pluginDescription;
}

// Return the category
QGISEXTERN QString category()
QGISEXTERN const QString *category()
{
return pluginCategory;
return &pluginCategory;
}

// Return the type (either UI or MapLayer plugin)
@@ -931,14 +931,14 @@ QGISEXTERN int type()
}

// Return the version number for the plugin
QGISEXTERN QString version()
QGISEXTERN const QString *version()
{
return pluginVersion;
return &pluginVersion;
}

QGISEXTERN QString icon()
QGISEXTERN const QString *icon()
{
return pluginIcon;
return &pluginIcon;
}

// Delete ourself
@@ -217,21 +217,21 @@ QGISEXTERN QgisPlugin *classFactory( QgisInterface *qgisInterfacePointer )

// Return the name of the plugin - note that we do not user class members as
// the class may not yet be insantiated when this method is called.
QGISEXTERN QString name()
QGISEXTERN const QString *name()
{
return sName;
return &sName;
}

// Return the description
QGISEXTERN QString description()
QGISEXTERN const QString *description()
{
return sDescription;
return &sDescription;
}

// Return the category
QGISEXTERN QString category()
QGISEXTERN const QString *category()
{
return sCategory;
return &sCategory;
}

// Return the type (either UI or MapLayer plugin)
@@ -241,14 +241,14 @@ QGISEXTERN int type()
}

// Return the version number for the plugin
QGISEXTERN QString version()
QGISEXTERN const QString *version()
{
return sPluginVersion;
return &sPluginVersion;
}

QGISEXTERN QString icon()
QGISEXTERN const QString *icon()
{
return sPluginIcon;
return &sPluginIcon;
}

// Delete ourself
@@ -195,30 +195,30 @@ typedef QgisPlugin *create_t( QgisInterface * );
typedef void unload_t( QgisPlugin * );

//! Typedef for getting the name of the plugin without instantiating it
typedef QString name_t();
typedef const QString *name_t();

//! Typedef for getting the description without instantiating the plugin
typedef QString description_t();
typedef const QString *description_t();

//! Typedef for getting the category without instantiating the plugin
typedef QString category_t();
typedef const QString *category_t();

//! Typedef for getting the plugin type without instantiating the plugin
typedef int type_t();

//! Typedef for getting the plugin version without instantiating the plugin
typedef QString version_t();
typedef const QString *version_t();

//! Typedef for getting the plugin icon file name without instantiating the plugin
typedef QString icon_t();
typedef const QString *icon_t();

//! Typedef for getting the experimental status without instantiating the plugin
typedef QString experimental_t();
typedef const QString *experimental_t();

//! Typedef for getting the create date without instantiating the plugin
typedef QString create_date_t();
typedef const QString *create_date_t();

//! Typedef for getting the update date status without instantiating the plugin
typedef QString update_date_t();
typedef const QString *update_date_t();

#endif // QGISPLUGIN_H

0 comments on commit b3c5cf8

Please sign in to comment.