declare the postal service iterators as values, not as references

PostalService.h names every type twice, once plainly and once as a reference:
RefToDestinationStruct is DestinationStruct&, RefToShipmentList is
ShipmentList&. That scheme was extended to the iterators, and there it does
not work. Every one of the seventeen uses looks like this:

    RefToShipmentListIterator sli = _Shipments.begin();

begin() returns a value, so this binds a non-const reference to a temporary.
MSVC allows it as an extension; the temporary still dies at the end of the
full expression, which leaves sli referring to a dead object for the whole
rest of the function. It works only because nothing has reused the stack slot
yet. clang rejects it outright.

Iterators are already handles into their container, so a reference to one buys
nothing: the plain typedef says exactly what these seventeen variables want to
be. DESTINATION and SHIPMENT now take theirs by value, which changes nothing
for either, as both only dereference the iterator they are given.

Two of the reference typedefs, RefToDestinationDeliveryInfoTableIterator and
RefToDeliveryCallbackDataListIterator, had no uses at all. They are removed
rather than left behind, since their only possible use is the pattern this
commit removes.

Verification:

    grep -rn 'RefTo[A-Za-z]*Iterator' --include=*.cpp --include=*.h .   # nothing
    ninja -C build parse         # bind-to-temporary class gone: 91 -> 60 sites
    ninja -C build -k 0          # Release, four applications, green
    ninja -C build-debug -k 0    # Debug, four applications, green

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
Marco Antonio J. Costa
2026-07-23 19:29:55 -03:00
committed by majcosta
co-authored by Claude Opus 4.8
parent 70b11ee120
commit b5ea70aa44
7 changed files with 22 additions and 26 deletions
+4 -7
View File
@@ -45,8 +45,8 @@ typedef DestinationStruct* PDestinationStruct;
typedef list<DestinationStruct> DestinationList;
typedef list<DestinationStruct>& RefToDestinationList;
typedef DestinationList::const_iterator& RefToDestinationListIterator;
inline RefToDestinationStruct DESTINATION(RefToDestinationListIterator dli)
typedef DestinationList::const_iterator DestinationListIterator;
inline RefToDestinationStruct DESTINATION(DestinationListIterator dli)
{
return ( (RefToDestinationStruct) *dli );
}
@@ -81,7 +81,6 @@ typedef vector<DestinationDeliveryInfoStruct> DestinationDeliveryInfoTable;
typedef DestinationDeliveryInfoTable* PDestinationDeliveryInfoTable;
typedef DestinationDeliveryInfoTable& RefToDestinationDeliveryInfoTable;
typedef DestinationDeliveryInfoTable::iterator DestinationDeliveryInfoTableIterator;
typedef DestinationDeliveryInfoTableIterator& RefToDestinationDeliveryInfoTableIterator;
typedef struct
{
@@ -104,7 +103,7 @@ typedef ShipmentPackageStruct& RefToShipmentPackageStruct;
typedef ShipmentPackageStruct* PShipmentPackageStruct;
typedef vector<ShipmentPackageStruct> ShipmentPackageList;
typedef ShipmentPackageList& RefToShipmentPackageList;
typedef ShipmentPackageList::iterator& RefToShipmentPackageListIterator;
typedef ShipmentPackageList::iterator ShipmentPackageListIterator;
typedef enum
{
@@ -130,7 +129,6 @@ typedef list<ShipmentStruct> ShipmentList;
typedef ShipmentList* PShipmentList;
typedef ShipmentList& RefToShipmentList;
typedef ShipmentList::iterator ShipmentListIterator;
typedef ShipmentListIterator& RefToShipmentListIterator;
typedef struct
{
@@ -159,7 +157,7 @@ inline BOOLEAN SHIPMENT_ID_LOWER(RefToShipmentStruct s1, RefToShipmentStruct s2)
}
#define SHIPMENT_LIST_ASCENDING SHIPMENT_ID_LOWER
inline RefToShipmentStruct SHIPMENT(RefToShipmentListIterator sli)
inline RefToShipmentStruct SHIPMENT(ShipmentListIterator sli)
{
return ( (RefToShipmentStruct) *sli );
}
@@ -192,7 +190,6 @@ typedef DeliveryCallbackDataStruct& RefToDeliveryCallbackDataStruct;
typedef vector<DeliveryCallbackDataStruct> DeliveryCallbackDataList;
typedef DeliveryCallbackDataList& RefToDeliveryCallbackDataList;
typedef DeliveryCallbackDataList::iterator DeliveryCallbackDataListIterator;
typedef DeliveryCallbackDataListIterator& RefToDeliveryCallbackDataListIterator;
////////////////////////////////////////////////////////////////
class CPostalService