[cfe-dev] Status of explicit conversion operators and nullptr

Douglas Gregor dgregor at apple.com
Wed Jul 20 10:51:28 PDT 2011


On Jul 20, 2011, at 9:19 AM, Jonathan Sauer wrote:

> Hello,
> 
> according to <http://clang.llvm.org/cxx_status.html>, explicit conversion operators are currently
> not really functional:
> 
> | No name mangling; ASTs don't contain calls to conversion operators
> 
> I just tried using them and to my delight they worked: Not only did the code compile (after I inserted
> the missing explicit casts), the resulting application ran without a hitch. To whomever implemented it:
> THANK YOU! :-)
> 
> The code I used them in was:
> 
> template <typename T, unsigned int FractBits>
> class Fixed {
>  ...
> 
>  // Convert to a float
>  explicit inline operator float() const;
> 
>  // Convert to any integer
>  template <typename U, typename std::enable_if<std::is_integral<U>::value, int>::type = 0>
>  explicit inline operator U() const;
> };
> 
> 
> I therefore think that the above status page should be updated at least to yellow ("many examples
> work").
> 
> The same goes for nullptr support: I have been using it successfully for weeks now (almost) without
> problems. Code generation most certainly isn't "broken". __has_feature(cxx_nullptr) also evaluates
> to "1".
> 
> Are these assessments correct (and should I send a patch for the status page), or am I overlooking
> something?


I don't believe that explicit conversions are fully implemented. At the very least, we need an audit + test cases for all of the places where we look at implicit conversions, to ensure that we're properly enabling/disabling explicit conversion functions at the right times.

nullptr is basically fully implemented. The only remaining issue I know of is that a thrown std::nullptr won't be caught as a T*, which is rather minor and might be more of a runtime issue . I'd appreciate it if you could send a patch for the status page!

	- Doug



More information about the cfe-dev mailing list