Brennan Vincent via llvm-dev
2017-Apr-08 20:59 UTC
[llvm-dev] Spurious cast warning for C++?
How difficult would it be to add a warning to Clang when the programmer performs a cast that provably has no effect? A particular case I have in mind is someone getting confused and calling std::move on an argument to a copy-constructor for a class that doesn't implement move semantics. I would be grateful if someone either (1) told me why this is difficult/impossible, or (2) gave me some pointers to where I could start trying to implement it...
This is question is probably better on the clang cfe-dev list. On Sun, Apr 9, 2017 at 12:01 PM Brennan Vincent via llvm-dev < llvm-dev at lists.llvm.org> wrote:> How difficult would it be to add a warning to Clang when the programmer > performs a cast that provably has no effect? > > A particular case I have in mind is someone getting confused and calling > std::move on an argument to a copy-constructor for a class that doesn't > implement move semantics. > > I would be grateful if someone either (1) told me why this is > difficult/impossible, or (2) gave me some pointers to where I could > start trying to implement it... > _______________________________________________ > LLVM Developers mailing list > llvm-dev at lists.llvm.org > http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev >-- ~Craig -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20170409/e38080eb/attachment.html>
mats petersson via llvm-dev
2017-Apr-10 09:39 UTC
[llvm-dev] Spurious cast warning for C++?
What does "have no effect" mean in this case? In my mind, there are many casts that have no effect - other than allowing the code to compile, which is quite an important effect in itself (e.g. casting a 32-bit unsigned to a pointer on your typical 32-bit system). Are you seeking to warn for: int a; int b; a = (int) b; and similar things? -- Mats On 9 April 2017 at 20:35, Craig Topper via llvm-dev <llvm-dev at lists.llvm.org> wrote:> This is question is probably better on the clang cfe-dev list. > > On Sun, Apr 9, 2017 at 12:01 PM Brennan Vincent via llvm-dev < > llvm-dev at lists.llvm.org> wrote: > >> How difficult would it be to add a warning to Clang when the programmer >> performs a cast that provably has no effect? >> >> A particular case I have in mind is someone getting confused and calling >> std::move on an argument to a copy-constructor for a class that doesn't >> implement move semantics. >> >> I would be grateful if someone either (1) told me why this is >> difficult/impossible, or (2) gave me some pointers to where I could >> start trying to implement it... >> _______________________________________________ >> LLVM Developers mailing list >> llvm-dev at lists.llvm.org >> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev >> > -- > ~Craig > > _______________________________________________ > LLVM Developers mailing list > llvm-dev at lists.llvm.org > http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev > >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20170410/3391c93b/attachment.html>
David Blaikie via llvm-dev
2017-Apr-10 14:33 UTC
[llvm-dev] Spurious cast warning for C++?
For the case of a redundant or unneeded std::move, I think Clang already has something like that... Ah, it doesn't quite catch that particular case. Richard - would it be reasonable to extend the pessimizing move warning (well, I guess not - maybe as a separate warning) for cases like this: void f(const foo&); void g(foo x) { f(std::move(x)); } Or maybe there's already a clang-tidy check for this sort of redundant move? On Sun, Apr 9, 2017 at 12:01 PM Brennan Vincent via llvm-dev < llvm-dev at lists.llvm.org> wrote:> How difficult would it be to add a warning to Clang when the programmer > performs a cast that provably has no effect? > > A particular case I have in mind is someone getting confused and calling > std::move on an argument to a copy-constructor for a class that doesn't > implement move semantics. > > I would be grateful if someone either (1) told me why this is > difficult/impossible, or (2) gave me some pointers to where I could > start trying to implement it... > _______________________________________________ > LLVM Developers mailing list > llvm-dev at lists.llvm.org > http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20170410/4ba08a79/attachment.html>
James Dennett via llvm-dev
2017-Apr-10 20:45 UTC
[llvm-dev] [cfe-dev] Spurious cast warning for C++?
On Sun, Apr 9, 2017 at 12:35 PM, Craig Topper via cfe-dev < cfe-dev at lists.llvm.org> wrote:> This is question is probably better on the clang cfe-dev list. > > On Sun, Apr 9, 2017 at 12:01 PM Brennan Vincent via llvm-dev < > llvm-dev at lists.llvm.org> wrote: > >> How difficult would it be to add a warning to Clang when the programmer >> performs a cast that provably has no effect? >> >> A particular case I have in mind is someone getting confused and calling >> std::move on an argument to a copy-constructor for a class that doesn't >> implement move semantics. >> >> I would be grateful if someone either (1) told me why this is >> difficult/impossible, or (2) gave me some pointers to where I could >> start trying to implement it... >> >clang-tidy has related diagnostics, such as those listed at https://clang.llvm.org/extra/clang-tidy/checks/misc-move-const-arg.html Not all of them are desirable, IMO, but clang-tidy (rather than clang-the-compiler) is the right place for them. -- James -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20170410/d3d8cbac/attachment.html>
Richard Smith via llvm-dev
2017-Apr-11 22:10 UTC
[llvm-dev] Spurious cast warning for C++?
On 10 April 2017 at 07:33, David Blaikie via llvm-dev < llvm-dev at lists.llvm.org> wrote:> For the case of a redundant or unneeded std::move, I think Clang already > has something like that... > > Ah, it doesn't quite catch that particular case. > > Richard - would it be reasonable to extend the pessimizing move warning > (well, I guess not - maybe as a separate warning) for cases like this: > > void f(const foo&); > void g(foo x) { > f(std::move(x)); > } > > Or maybe there's already a clang-tidy check for this sort of redundant > move? >There's already a clang warning for redundant moves (-Wredundant-move). It doesn't yet catch the above pattern, but it should...> On Sun, Apr 9, 2017 at 12:01 PM Brennan Vincent via llvm-dev < > llvm-dev at lists.llvm.org> wrote: > >> How difficult would it be to add a warning to Clang when the programmer >> performs a cast that provably has no effect? >> >> A particular case I have in mind is someone getting confused and calling >> std::move on an argument to a copy-constructor for a class that doesn't >> implement move semantics. >> >> I would be grateful if someone either (1) told me why this is >> difficult/impossible, or (2) gave me some pointers to where I could >> start trying to implement it... >> _______________________________________________ >> LLVM Developers mailing list >> llvm-dev at lists.llvm.org >> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev >> > > _______________________________________________ > LLVM Developers mailing list > llvm-dev at lists.llvm.org > http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev > >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20170411/e0b0d6e6/attachment-0001.html>