llvm / llvm-project

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

[QOI] warn about free functions which shadow one in a namespace #6739

Open llvmbot opened 14 years ago

llvmbot commented 14 years ago
Bugzilla Link 6367
Version unspecified
OS All
Reporter LLVM Bugzilla Contributor
CC @DougGregor,@zygoloid

Extended Description

I would like clang to optionally warn me about 'f0' in this:

ddunbar@giles:tmp$ cat t.cpp

void f1();
namespace foo {
  void f0();
  void f1();
}
void f0() {} // expected-warning {{something nice}}
void f1() {}

ddunbar@giles:tmp$ clang -Wall -c t.cpp ddunbar@giles:tmp$

I almost never care to implement a non-static, undeclared function. I want clang to point out that I am doing this when it can find a 'f0' inside a different namespace. I want a fixit for adding 'foo::'.

ec04fc15-fa35-46f2-80e1-5d271f2ef708 commented 13 years ago

A related case:

struct S { void f() const; int n; };

void f() const { n = 0; }

It'd be amazing if clang could suggest adding "S::" to this function definition. This case is arguably easier, since an ill-formed cv-qualifier (or ref-qualifier) on a function definition is a big giveaway that it was meant to be a member function: we can give an error with a fixit here, whereas the namespace case would have to be just a warning (with a fixit in a note).

We can make this check faster (and weed out false positives) by only looking in classes and namespaces for which we've already seen at least one out-of-line function definition in this TU.

DougGregor commented 14 years ago

It's kind of like -Wmissing-prototypes for C++. It should not apply to templates or member functions.

llvmbot commented 1 year ago

@llvm/issue-subscribers-clang-tidy

philnik777 commented 1 year ago

I think this kind of diagnostic makes more sense as a clang-tidy check, since this heavily depends on how your code base looks.