On 14 Feb 2018 8:16 pm, "Pedro Alves" <pal...@redhat.com> wrote:
Instead of a class that has to have a constructor for every type you want to pass as plural selector to the _n functions, which increases coupling, I'd suggest using a conversion function, and overload that. I.e., something like, in the core diagnostics code: static inline unsigned HOST_WIDE_INT as_plural_form (unsigned HOST_WIDE_INT val) { return val; } /* In some tree-diagnostics header. */ static inline unsigned HOST_WIDE_INT as_plural_form (tree t) { // extract & return a HWI } /* In some whatever-other-type-diagnostics header. */ static inline unsigned HOST_WIDE_INT as_plural_form (whatever_other_type v) { // like above } and then you call error_n and other similar functions like this: error_n (loc, u, "%u thing", "%u things", u); error_n (loc, as_plural_form (u), "%u thing", "%u things", u); error_n (loc, as_plural_form (t), "%E thing", "%E things", t); error_n (loc, as_plural_form (i), "%wu thing", "%wu things", i); This is similar in spirit to std::to_string, etc. If that's desired, why not simply have GCC::to_uhwi() ? It would likely be useful in other contexts. Cheers, Manuel.