C++ covariant return types

Description

One of the pain points with using ICU C++ API is that some of our subclass functions return pointer-to-base-class, just because 20 years ago some compilers didn't support covariant return types.

(FYI: In Java, covariant return types are supported since Java 5: )

For example, UnicodeSet clone() and freeze() return pointers to the UnicodeFunctor base class, so you can't just write

Instead you have to

Could we change our clone(), freeze(), and similar functions to return same-as-this types?

Activity

Show:
Markus Scherer
August 22, 2019, 9:19 PM

Andy wrote in a PR comment:

This regular expression: (.*).*clone( finds a fair number of clones with casts, where the cast could potentially be removed.

Markus Scherer
August 22, 2019, 9:34 PM

With (\\(.*\\)|_cast\\<).*clone
( I get 228 matches, a number of them false positives.

Fixed

Assignee

Markus Scherer

Reporter

Markus Scherer

Components

Labels

None

Reviewer

None

Priority

medium

Time Needed

Hours

Fix versions

Configure