llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
27.93k stars 11.53k forks source link

Warn on usage of -> on array #12746

Open llvmbot opened 12 years ago

llvmbot commented 12 years ago
Bugzilla Link 12374
Version unspecified
OS All
Reporter LLVM Bugzilla Contributor
CC @DougGregor,@gribozavr

Extended Description

Version: Apple clang version 3.1 (tags/Apple/clang-318.0.58) (based on LLVM 3.1svn) Target: x86_64-apple-darwin11.3.0 Thread model: posix

compiled with -Weverything

The following should generate a warning:

struct s { void f(); }

int main(int argc, char* argv[]) { s vals[4]; vals->f();

return 0; }

it is unlikely that a user wants to access the first element of an array by using vals->f(); rather than vals[0].f();

DougGregor commented 12 years ago

Re-opening because I'm not totally against it, but someone will have to go implement it and assess whether it's actually a useful warning.

DougGregor commented 12 years ago

I'm on the fence about this one. I can't see any reason to use -> on an array, yet it also seems unlikely that a user would actually make this mistake and still get the program to type-check. We'd just have to implement it and run it across a pile of code to see how many bugs vs. false positives it finds.

llvmbot commented 12 years ago

This is a coding standards sort of thing, not likely to be indicative of a bug.

I would think that this is similar to choosing to throw a warning on assignment inside a conditional. It is valid c++ but unlikely to be intentional and almost always a bug.

Is there a specific pattern/example where acting on a fixed-size array using -> is desired?

lattner commented 12 years ago

This is a coding standards sort of thing, not likely to be indicative of a bug.