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

Disable google-readability-casting as it is broken. #3958

Closed

Conversation

chandlerc
Copy link
Contributor

I had been bothered by the confusing suggestions to replace calls to a constructor with ... calls to a constructor, claiming the original code was a C-style cast. In some code, we've worked around this by using static_cast but that really doesn't seem to be a readability win.

I did some research and from what I can tell this tidy check is deeply broken, with both Chromium and internal Google users disabling it due to widespread issues:
https://chromium.googlesource.com/chromium/src/+/f828a2248f0da4e7bfadfa5db324230043aaea02

We should disable it as well for now. I've removed one NOLINT comment for it, but not tried to remove all the static_casts that are now unnecessary as that seems hard to do in any automatic way.

Replace this paragraph with a description of what this PR is changing or
adding, and why.

Closes #ISSUE

I had been bothered by the confusing suggestions to replace calls to
a constructor with ... calls to a constructor, claiming the original
code was a C-style cast. In some code, we've worked around this by using
`static_cast` but that really doesn't seem to be a readability win.

I did some research and from what I can tell this tidy check is deeply
broken, with both Chromium and internal Google users disabling it due to
widespread issues:
https://chromium.googlesource.com/chromium/src/+/f828a2248f0da4e7bfadfa5db324230043aaea02

We should disable it as well for now. I've removed one `NOLINT` comment
for it, but not tried to remove all the `static_cast`s that are now
unnecessary as that seems hard to do in any automatic way.
@jonmeow
Copy link
Contributor

jonmeow commented May 20, 2024

We should disable it as well for now. I've removed one NOLINT comment for it, but not tried to remove all the static_casts that are now unnecessary as that seems hard to do in any automatic way.

Isn't this tidy check only warning about C-style casts? i.e., from a style perspective, doesn't Google's casting style still apply? If there are false positives for constructors, that would change. But we would still frequently be casting due to things like int vs size_t comparisons (which are probably the most frequent case). As a consequence, static_cast would remain. I see the one false positive here, but aren't the other uses of static_cast [ed: and reinterpret_cast, const_cast] correct?

That is to say, we have the occasional false positive, but also we use C++ casts a lot. If someone unfamiliar with Google C++ style comes along and starts adding C-style casts, is it going to be a net improvement if we're correcting the style in review? Should style change to instead encourage C-style casts?

@@ -21,6 +21,10 @@ WarningsAsErrors: '*'
# inst_id = name_ref->value_id;
# ^ unchecked access to optional value
# }
# - google-readability-casting is deeply broken, and fires regularly on calls
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we're moving forward with this, is there an issue you can link to?

Comment on lines +24 to +27
# - google-readability-casting is deeply broken, and fires regularly on calls
# to constructors. Worse, it suggests switching to a call to a constructor
# which doesn't fix the warning. This has been disabled by many major users
# of clang-tidy (Chromium, etc).
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note, the way you're talking about this issue is pretty strong. Would it be worth softening up the wording for other readers? e.g., maybe we could focus on the issue as it affects us:

Suggested change
# - google-readability-casting is deeply broken, and fires regularly on calls
# to constructors. Worse, it suggests switching to a call to a constructor
# which doesn't fix the warning. This has been disabled by many major users
# of clang-tidy (Chromium, etc).
# - google-readability-casting fires regularly on calls to constructors. It suggests switching to a call to a constructor, which doesn't fix the warning.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note too, you might also consider rephrasing the PR title and description.

@jonmeow
Copy link
Contributor

jonmeow commented May 20, 2024

I should also ask here, is this also an issue with {} constructor syntax? What's the code that you were trying to write that you ran into this?

[ed: to be sure -- it's not clear to me from https://crbug.com/1282228 whether they considered brace-based init as a possible solution]

@chandlerc
Copy link
Contributor Author

Well, after a huge debugging session that should have been much shorter (Jon told me exactly what command I should run to confirm my assumption, and I took way to long to run it), I understand the issue better now.

There was some bug at some point or in some patched versions of clang-tidy and clangd here. But the reason there are few references to it any more is that these bugs got fixed. And in fact modern clang-tidy and clangd are completely correct here.

At some point, I was sure there weren't other versions of clangd available on macOS, but if that was true once, it isn't true now -- there is a version shipped in Xcode that VSCode knew how to find and has the specific bug in this check I was seeing. Anyways, I'm using the right version and we can delete this PR. I'll see abotu adding an FAQ entry about accidentally getting the wrong clangd in your IDE.

@chandlerc chandlerc closed this May 21, 2024
@zygoloid
Copy link
Contributor

I'm still seeing problems with this check in our CI. Should we disable the check?

github-merge-queue bot pushed a commit that referenced this pull request May 31, 2024
Following discussions around #3958, try to provide more specific
semantics. Note we currently don't follow this everywhere, particularly
in AddInst calls, but the intent is to shift. Per discussion, designated
initializers are preferred when possible. And the
`google-readability-casting` diagnostics are poor, but with this may
primarily flag cases which should be using a different constructor
syntax, so are just a rocky way to get there.

---------

Co-authored-by: Richard Smith <richard@metafoo.co.uk>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants