[Qgis-psc] QEP 314: Relax prohibition against "auto" for results of casting operations

Nyall Dawson nyall.dawson at gmail.com
Sun Feb 23 14:31:05 PST 2025


Hi all,

Please see https://github.com/qgis/QGIS-Enhancement-Proposals/pull/330
for a proposed change to the QGIS coding policies to relax the current
prohibition against use of "auto" in some (more!) new cases.

(This follows up recent changes to permit auto for smart pointer types, see
https://github.com/qgis/QGIS-Enhancement-Proposals/pull/319)

This change relaxes the prohibition against auto to allow use of auto for
variable types when the variable type is explicitly stated during its
initialization as the result of a cast operation, such as dynamic_cast,
static_cast, const_cast, reinterpret_cast, qobject_cast,
qgsgeometry_cast, or qgis::down_cast

Specifically:

// allowed, the pointer types are explicit during initialization:
auto markerSymbol = dynamic_cast< QgsMarkerSymbol* >( symbol );
auto vectorLayer = qobject_cast< QgsVectorLayer* >( layer );
if ( auto lineString = qgsgeometry_cast< const QgsLineString* >( geometry )
) { ... }

// NOT allowed, the type is not explicit:
auto myLineStringPtr = downcastGeometryAsLineString( geometry );

Please keep discussion on
https://github.com/qgis/QGIS-Enhancement-Proposals/pull/330 so that we
have a formal record of the discussion.

Thanks all!
Nyall
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-psc/attachments/20250224/e29f6a84/attachment.htm>


More information about the QGIS-PSC mailing list