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

1 return new UnicodeSet(pattern)->freeze();

Instead you have to

1 2 3 UnicodeSet *set = new UnicodeSet(pattern); set->freeze(); return set;

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

Status

Assignee

Markus Scherer

Reporter

Markus Scherer

Labels

None

Reviewer

None

Time Needed

Hours

Start date

None

Components

Fix versions

Priority

medium