diff --git a/icu4c/source/i18n/choicfmt.cpp b/icu4c/source/i18n/choicfmt.cpp index cdae34770e..2525d40ae9 100644 --- a/icu4c/source/i18n/choicfmt.cpp +++ b/icu4c/source/i18n/choicfmt.cpp @@ -132,7 +132,6 @@ UBool ChoiceFormat::operator==(const Format& that) const { if (this == &that) return TRUE; - if (this->getDynamicClassID() != that.getDynamicClassID()) return FALSE; // not the same class if (!NumberFormat::operator==(that)) return FALSE; ChoiceFormat& thatAlias = (ChoiceFormat&)that; if (fCount != thatAlias.fCount) return FALSE; diff --git a/icu4c/source/i18n/datefmt.cpp b/icu4c/source/i18n/datefmt.cpp index 0a216916b9..4dc0ce8ca9 100644 --- a/icu4c/source/i18n/datefmt.cpp +++ b/icu4c/source/i18n/datefmt.cpp @@ -90,14 +90,13 @@ DateFormat::operator==(const Format& other) const // which have confirmed that the other object being compared against is // an instance of a sublcass of DateFormat. THIS IS IMPORTANT. - // We only dereference this pointer after we have confirmed below that - // 'other' is a DateFormat subclass. + // Format::operator== guarantees that this cast is safe DateFormat* fmt = (DateFormat*)&other; return (this == fmt) || - ((getDynamicClassID() == other.getDynamicClassID()) && + (Format::operator==(other) && fCalendar&&(fCalendar->isEquivalentTo(*fmt->fCalendar)) && - (fNumberFormat&&(*fNumberFormat == *fmt->fNumberFormat)) ); + (fNumberFormat && *fNumberFormat == *fmt->fNumberFormat)); } //---------------------------------------------------------------------- diff --git a/icu4c/source/i18n/format.cpp b/icu4c/source/i18n/format.cpp index 5e1615f528..78debaef21 100644 --- a/icu4c/source/i18n/format.cpp +++ b/icu4c/source/i18n/format.cpp @@ -132,10 +132,10 @@ Format::parseObject(const UnicodeString& source, // ------------------------------------- UBool -Format::operator==(const Format& /*that*/) const +Format::operator==(const Format& that) const { - // Add this implementation to make linker happy. - return TRUE; + // Subclasses: Call this method and then add more specific checks. + return getDynamicClassID() == that.getDynamicClassID(); } //--------------------------------------- diff --git a/icu4c/source/i18n/msgfmt.cpp b/icu4c/source/i18n/msgfmt.cpp index 55db180891..a97971352e 100644 --- a/icu4c/source/i18n/msgfmt.cpp +++ b/icu4c/source/i18n/msgfmt.cpp @@ -392,7 +392,6 @@ MessageFormat::operator==(const Format& rhs) const // Check class ID before checking MessageFormat members if (!Format::operator==(rhs) || - getDynamicClassID() != that.getDynamicClassID() || fPattern != that.fPattern || fLocale != that.fLocale) { return FALSE; diff --git a/icu4c/source/i18n/smpdtfmt.cpp b/icu4c/source/i18n/smpdtfmt.cpp index bbaeb72dba..1c11e22efe 100644 --- a/icu4c/source/i18n/smpdtfmt.cpp +++ b/icu4c/source/i18n/smpdtfmt.cpp @@ -249,9 +249,8 @@ SimpleDateFormat::clone() const UBool SimpleDateFormat::operator==(const Format& other) const { - if (DateFormat::operator==(other) && - other.getDynamicClassID() == getStaticClassID()) - { + if (DateFormat::operator==(other)) { + // DateFormat::operator== guarantees following cast is safe SimpleDateFormat* that = (SimpleDateFormat*)&other; return (fPattern == that->fPattern && fSymbols != NULL && // Check for pathological object