Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hb-iter-private.hh:75:3: error: bad implicit conversion operator for 'Iter<const int *>' with HB 1.8.5 #1127

Closed
rvandermeulen opened this issue Aug 6, 2018 · 9 comments

Comments

@rvandermeulen
Copy link
Contributor

Hi, I'm looking at updating HarfBuzz in Firefox and our clang static analysis checker is hitting the below errors:

INFO -  /builds/worker/workspace/build/src/gfx/harfbuzz/src/hb-iter-private.hh:75:3: error: bad implicit conversion operator for 'Iter<const int *>'
INFO -    inline operator bool (void) const { return bool (length); }
INFO -    ^
INFO -  /builds/worker/workspace/build/src/gfx/harfbuzz/src/hb-iter-private.hh:75:3: note: consider adding the explicit keyword to 'operator bool'
INFO -  /builds/worker/workspace/build/src/gfx/harfbuzz/src/hb-iter-private.hh:75:3: error: bad implicit conversion operator for 'Iter<int *>'
INFO -    inline operator bool (void) const { return bool (length); }
INFO -    ^
INFO -  /builds/worker/workspace/build/src/gfx/harfbuzz/src/hb-iter-private.hh:75:3: note: consider adding the explicit keyword to 'operator bool'
INFO -  /builds/worker/workspace/build/src/gfx/harfbuzz/src/hb-iter-private.hh:75:3: error: bad implicit conversion operator for 'Iter<T *>'
INFO -    inline operator bool (void) const { return bool (length); }
INFO -  /builds/worker/workspace/build/src/gfx/harfbuzz/src/hb-iter-private.hh:75:3: note: consider adding the explicit keyword to 'operator bool'

I can confirm that adding an explicit to that line resolves the errors.

@behdad
Copy link
Member

behdad commented Aug 6, 2018

I like it to be implicit though. What's bad about it?

I'm going to make a new release later today, if you want to wait.

@behdad
Copy link
Member

behdad commented Aug 6, 2018

Ie. I want the iterators to be used in for loops like: for (Iter<T> t (...); t; t++).

@behdad
Copy link
Member

behdad commented Aug 6, 2018

Or is that too much magic?

@rvandermeulen
Copy link
Contributor Author

Hmm, this check has been in our code base for about 3 years now (bug 1153348). We do allow for a MOZ_IMPLICIT annotation on lines we don't want to mark as explicit, but that obviously seems a tad non-ideal for upstream libraries 😃.

I believe I can opt HarfBuzz out of that specific static analysis check as well, but that seems like the only real option here if using explicit isn't what you want.

@behdad
Copy link
Member

behdad commented Aug 6, 2018

We haven't started using that idiom yet. I understand why it's desirable to ban it. I think I'm fine making it explicit.

@behdad behdad closed this as completed in 66920a6 Aug 6, 2018
@behdad
Copy link
Member

behdad commented Aug 7, 2018

Released 1.8.6 with this change.

@behdad
Copy link
Member

behdad commented Aug 9, 2018

Some of our compilers (Oracle Studio and Apple gcc 4.2) do not like explicit on non-constructors :(.
https://circleci.com/gh/harfbuzz/harfbuzz/30289

I think I'll revert this. Do you think you can handle it on your side?

behdad added a commit that referenced this issue Aug 9, 2018
This reverts commit 66920a6.

Some of our bots (Oracle Studio and Apple gcc 4.2) do not allow
explicit except for constructors.

#1127
@behdad behdad reopened this Aug 9, 2018
@rvandermeulen
Copy link
Contributor Author

rvandermeulen commented Aug 9, 2018 via email

@behdad
Copy link
Member

behdad commented Aug 11, 2018

Actually, I think I'll take care of this by enabling the explicit only in C++11 or later. Reading https://en.cppreference.com/w/cpp/language/explicit reminds me believe that if and for statements perform an explicit cast to bool, so I was wrong that we would need to write "for (...; bool(it); ...)" if I add explicit.

You don't need to do anything. I'll fix this.

@behdad behdad closed this as completed in f9a3eab Aug 12, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants