[PATCH] D86120: [NFC][llvm] Make the constructors of `ElementCount` private.

Francesco Petrogalli via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Aug 20 08:48:24 PDT 2020


fpetrogalli added a comment.

In D86120#2228000 <https://reviews.llvm.org/D86120#2228000>, @davezarzycki wrote:

> Why were static "get" methods preferred over simply marking the constructor `explicit`? For example, if the constructor is marked explicit, then this is what users see:
>
>       llvm::ElementCount EC = {vector->getNumElements(), /*scalable*/ false};
>                          ^    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>   /home/dave/s/n/llvm/include/llvm/Support/TypeSize.h:37:12: note: explicit constructor declared here
>     explicit ElementCount(unsigned Min, bool Scalable) : Min(Min), Scalable(Scalable) {}
>              ^
>   1 error generated.

Hi @davezarzycki ,

thank you for your comment. The idea of introducing `get*` methods was to make sure the users would make a conscious decision about  whether they where setting up Fixed o Scalable instances of `ElementCount`.  As for the general constructor you mention, we could have 1. allowed people to use initializer lists for ElementCount or alternatively 2. mark the constructor as explicit. With @ctetreau we decided to have an uniform approach, so we decided to allow building instances of ElementCount only via static methods. So, no real technical reason for not using "explicit", other than our preference.

Kind regards,

Francesco


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D86120/new/

https://reviews.llvm.org/D86120



More information about the llvm-commits mailing list