llvm / llvm-project

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

Missing warning deprecated copy constructor warning in -Wextra #95

Open roe85 opened 4 years ago

roe85 commented 4 years ago

There seems to be some interference between -Wdeprecated-copy-dtor and -Wdeprecated-copy which leads to emitting only the first one. Demo: https://gcc.godbolt.org/z/_8Dx4K This is bad because only the second is governed by -Wextra, which is likelier to be activated. The code attached is not warned about whith -Wextra unless the destructor is commented out. GCC warns in either case. I think there is no reason, why both warnings shouldn't be governed with -Wextra.

class A {
    public:
    void b();
    ~A();
    A& operator=(const A& a);

};
void test() {

    A a;

    A b = a;
    a = b;

    (void)a;
    (void)b;
}
Quuxplusone commented 2 years ago

This behavior was altered beyond recognition by the fix for #44979, so maybe this can be closed. -Wdeprecated now says:

<source>:6:5: warning: definition of implicit copy constructor for 'A' is deprecated because it has a user-provided destructor [-Wdeprecated-copy-with-user-provided-dtor]
    ~A();
    ^
<source>:14:11: note: in implicit copy constructor for 'A' first required here
    A b = a;
          ^

But this warning is still enabled only by -Wdeprecated, not by -Wall or -Wextra. I think it would be nice to enable it under -Wextra, at least, since it does usually indicate a bug or at least a time bomb.

llvmbot commented 2 years ago

@llvm/issue-subscribers-c-1