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

misc-string-integer-assignment doesn't work #26507

Closed
llvmbot opened this issue Jan 13, 2016 · 13 comments
Closed

misc-string-integer-assignment doesn't work #26507

llvmbot opened this issue Jan 13, 2016 · 13 comments
Assignees
Labels
bugzilla Issues migrated from bugzilla clang-tidy

Comments

@llvmbot
Copy link
Collaborator

llvmbot commented Jan 13, 2016

Bugzilla Link 26133
Resolution FIXED
Resolved on Feb 06, 2016 17:09
Version unspecified
OS Linux
Attachments short file, preprocessed file
Reporter LLVM Bugzilla Contributor
CC @kirillbobyrev

Extended Description

Hi guys,
I been recently playing with clang-tidy, and I don't know why but some checks seems to not check for what they should.
I took simple example from docs (included file).
I am sure I am running right checks, because list checks say so.

@llvmbot
Copy link
Collaborator Author

llvmbot commented Jan 13, 2016

assigned to @Xazax-hun

@llvmbot
Copy link
Collaborator Author

llvmbot commented Jan 15, 2016

What standard library do you use? With the version of libstdc++ I have on my machine, this seems to work (with the preprocessed file it doesn't):

$ cat /tmp/qq.cc
#include

int main() {
std::string s;
int x = 5965;
s = 6;
s = x;
}
$ clang-tidy -checks=-*,misc-string-integer-assignment /tmp/qq.cc --
2 warnings generated.
/tmp/qq.cc:6:9: warning: an integer is interpreted as a character code when assigning it to a string; if this is intended, cast the integer to the appropriate character type; if you want a string representation, use the appropriate conversion facility [misc-string-integer-assignment]
s = 6;
^
''
/tmp/qq.cc:7:9: warning: an integer is interpreted as a character code when assigning it to a string; if this is intended, cast the integer to the appropriate character type; if you want a string representation, use the appropriate conversion facility [misc-string-integer-assignment]
s = x;
^

@llvmbot
Copy link
Collaborator Author

llvmbot commented Jan 15, 2016

Seems to be a problem with inline namespace __cxx11 {} again. Is this exactly the problem that http://reviews.llvm.org/D15506 is meant to solve?

@Xazax-hun
Copy link
Collaborator

Seems to be a problem with inline namespace __cxx11 {} again. Is this
exactly the problem that http://reviews.llvm.org/D15506 is meant to solve?

I think so.

@llvmbot
Copy link
Collaborator Author

llvmbot commented Jan 15, 2016

May I ask you to apply that patch and see whether it fixes the issue?

@Xazax-hun
Copy link
Collaborator

May I ask you to apply that patch and see whether it fixes the issue?

Sure! I can confirm that after applying the patch from http://reviews.llvm.org/D15506 the checker can find the two issues in the attached preprocessed file.

@kirillbobyrev
Copy link
Member

Looking into this patch:

Allow hasName() to look through inline namespaces.

This seems to be quite unexpected behaviour. Isn't just applying regular expressions via using matchesName instead of hasName while leaving hasName with more intuitive behaviour?

@Xazax-hun
Copy link
Collaborator

Looking into this patch:

Allow hasName() to look through inline namespaces.

This seems to be quite unexpected behaviour. Isn't just applying regular
expressions via using matchesName instead of hasName while leaving hasName
with more intuitive behaviour?

Inline namespaces are often implementation details. I don't think that the checkers should deal with them unless they really want to. And I think it is unreasonable to expect the checker authors to test their checkers with all of the major standard libraries to check whether their regexp is correct for all of them.

@kirillbobyrev
Copy link
Member

Looking into this patch:

Allow hasName() to look through inline namespaces.

This seems to be quite unexpected behaviour. Isn't just applying regular
expressions via using matchesName instead of hasName while leaving hasName
with more intuitive behaviour?

Inline namespaces are often implementation details. I don't think that the
checkers should deal with them unless they really want to. And I think it is
unreasonable to expect the checker authors to test their checkers with all
of the major standard libraries to check whether their regexp is correct for
all of them.

Makes sense.

I was about to suggest creating a custom matcher, say, hasNameThroughNamespaces or something less monstrous, but I can't find a scenario, when somebody will want to use the hasName with exact inline etc namespaces matching.

@Xazax-hun
Copy link
Collaborator

Looking into this patch:

Allow hasName() to look through inline namespaces.

This seems to be quite unexpected behaviour. Isn't just applying regular
expressions via using matchesName instead of hasName while leaving hasName
with more intuitive behaviour?

Inline namespaces are often implementation details. I don't think that the
checkers should deal with them unless they really want to. And I think it is
unreasonable to expect the checker authors to test their checkers with all
of the major standard libraries to check whether their regexp is correct for
all of them.

Makes sense.

I was about to suggest creating a custom matcher, say,
hasNameThroughNamespaces or something less monstrous, but I can't find a
scenario, when somebody will want to use the hasName with exact inline etc
namespaces matching.

I can think of one scenario, to warn when a deprecated version of an API is used, that is behind an inline namespace, and the library authors did not add the deprecated attribute to the API. But this is probably very rare.

@llvmbot
Copy link
Collaborator Author

llvmbot commented Jan 15, 2016

Thanks guys, I am waiting till this patch will be upstream.

@llvmbot
Copy link
Collaborator Author

llvmbot commented Feb 4, 2016

What is the status of it?

Thanks guys, I am waiting till this patch will be upstream.

@llvmbot
Copy link
Collaborator Author

llvmbot commented Feb 7, 2016

Thanks for fixing!

@llvmbot llvmbot transferred this issue from llvm/llvm-bugzilla-archive Dec 10, 2021
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugzilla Issues migrated from bugzilla clang-tidy
Projects
None yet
Development

No branches or pull requests

3 participants