[Bug c++/79078] Warnings from deprecated attribute are too noisy

2022-02-17 Thread jason at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=79078

Jason Merrill  changed:

   What|Removed |Added

 CC||jason at gcc dot gnu.org

--- Comment #18 from Jason Merrill  ---
(In reply to Jonathan Wakely from comment #13)
> Comment 1 and comment 2 are fixed by PR 84222.
> 
> Comment 3 now only gives three warnings (for the three uses of D in the
> non-member function) not five warnings. The warnings within the class are
> gone, but no improvement for the non-member function.
> 
> Similarly, comment 5 has two fewer warnings (five not seven).

comment 5 seems to have been fixed in GCC 11 to get only two warnings.  The
three warnings for comment 3 are suboptimal, but seem reasonable given that
there are in fact three uses of the deprecated declaration.  Likewise the two
warnings for comment 0.

[Bug c++/79078] Warnings from deprecated attribute are too noisy

2020-07-30 Thread redi at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=79078

--- Comment #17 from Jonathan Wakely  ---
(In reply to Jonathan Wakely from comment #16)
> struct string
> {
> #if __cplusplus == 201703L
>   [[deprecated("use shrink_to_fit() instead")]]
> #elif __cplusplus > 201703L
> private:
> #endif
>   void reserve()
>   { }
> public:

The solution here is to just disable the warning around this use:

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"

>   void shrink_to_fit() { reserve(); }

#pragma GCC diagnostic pop

> };

So I don't need a compiler change after all.

[Bug c++/79078] Warnings from deprecated attribute are too noisy

2020-07-30 Thread redi at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=79078

--- Comment #16 from Jonathan Wakely  ---
(In reply to Marek Polacek from comment #8)
> One thing we should do is to
> 
> --- a/gcc/cp/decl.c
> +++ b/gcc/cp/decl.c
> @@ -12643,7 +12643,7 @@ grokparms (tree parmlist, tree *parms)
>   if (deprecated_state != DEPRECATED_SUPPRESS)
> {
>   tree deptype = type_is_deprecated (type);
> - if (deptype)
> + if (deptype && !TYPE_BEING_DEFINED (deptype))
> warn_deprecated_use (deptype, NULL_TREE);
> }
>  
> 
> i.e. don't warn if the deprecated type is being defined.

That looks sensible, but only helps for uses of the type. It doesn't help this
case where a function is deprecated (this is based on a real change I want to
make to libstdc++):


struct string
{
#if __cplusplus == 201703L
  [[deprecated("use shrink_to_fit() instead")]]
#elif __cplusplus > 201703L
private:
#endif
  void reserve()
  { }
public:

  void shrink_to_fit() { reserve(); }
};

int main()
{
  string s;
  s.shrink_to_fit();
}

When compiled as C++17 this issues a deprecated warning for the call from
shrink_to_fit(). The user of the class never calls the deprecated function
though. Calling it from another member of the class should not warn.

Marek, do you have a suggestion for how to suppress this one?

It would be very helpful to get a quick fix for this part, even if Martin's
more ambitious plan in comment 14 isn't going to be ready in the short term.

[Bug c++/79078] Warnings from deprecated attribute are too noisy

2018-06-25 Thread jakub at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=79078
Bug 79078 depends on bug 84222, which changed state.

Bug 84222 Summary: [6/7 Regression] [[deprecated]] class complains about 
internal class usage
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=84222

   What|Removed |Added

 Status|NEW |RESOLVED
 Resolution|--- |FIXED

[Bug c++/79078] Warnings from deprecated attribute are too noisy

2018-03-21 Thread redi at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=79078

--- Comment #15 from Jonathan Wakely  ---
I think that would work well.

[Bug c++/79078] Warnings from deprecated attribute are too noisy

2018-03-21 Thread msebor at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=79078

--- Comment #14 from Martin Sebor  ---
For non-member functions that are part of a class API I would like to see about
getting the following to work for types (as it already does for functions):

1) define a class with no attribute
2) define the API that uses the class without triggering warnings
3) declare the class [[deprecated]]
4) have any subsequent uses of the class trigger warnings

Like this:

$ cat u.C && gcc -S -Wall -Wextra -Wpedantic u.C
struct A;

int f (A*);

int i = f (0);

struct A { };

int g (A); // no warning

int j = g (A ());  // no warning

struct [[deprecated]] A;   // add attribute, expect no warning

int h (A); // expect warning

u.C:13:23: warning: type attributes ignored after type is already defined
[-Wattributes]
 struct [[deprecated]] A;   // add attribute, expect no warning
   ^

Currently it doesn't work because for structs, GCC doesn't apply attributes
from declarations, only on definitions (this is bug 81756, at least in part).

Does it resolve the outstanding issues?  Are there any concerns with it?

[Bug c++/79078] Warnings from deprecated attribute are too noisy

2018-03-21 Thread redi at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=79078

Jonathan Wakely  changed:

   What|Removed |Added

   Last reconfirmed|2017-01-13 00:00:00 |2018-3-21

--- Comment #13 from Jonathan Wakely  ---
Comment 1 and comment 2 are fixed by PR 84222.

Comment 3 now only gives three warnings (for the three uses of D in the
non-member function) not five warnings. The warnings within the class are gone,
but no improvement for the non-member function.

Similarly, comment 5 has two fewer warnings (five not seven).

[Bug c++/79078] Warnings from deprecated attribute are too noisy

2017-08-24 Thread egallager at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=79078

Eric Gallager  changed:

   What|Removed |Added

 CC||chrisb2244 at gmail dot com

--- Comment #12 from Eric Gallager  ---
*** Bug 67960 has been marked as a duplicate of this bug. ***

[Bug c++/79078] Warnings from deprecated attribute are too noisy

2017-04-24 Thread daniel.kruegler at googlemail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=79078

--- Comment #11 from Daniel Krügler  ---
(In reply to Jonathan Wakely from comment #10)
> (In reply to Daniel Krügler from comment #9)
> > PR 61754 seems to be related.
> 
> I think for the examples here it makes no difference if you use
> __attribute__((deprecated(""))) or [[deprecated("")]]

Oops, you are right, I was mislead!

[Bug c++/79078] Warnings from deprecated attribute are too noisy

2017-04-24 Thread redi at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=79078

--- Comment #10 from Jonathan Wakely  ---
(In reply to Daniel Krügler from comment #9)
> PR 61754 seems to be related.

I think for the examples here it makes no difference if you use
__attribute__((deprecated(""))) or [[deprecated("")]]

[Bug c++/79078] Warnings from deprecated attribute are too noisy

2017-04-24 Thread daniel.kruegler at googlemail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=79078

Daniel Krügler  changed:

   What|Removed |Added

 CC||daniel.kruegler@googlemail.
   ||com

--- Comment #9 from Daniel Krügler  ---
PR 61754 seems to be related.

[Bug c++/79078] Warnings from deprecated attribute are too noisy

2017-04-20 Thread mpolacek at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=79078

Marek Polacek  changed:

   What|Removed |Added

 CC||mpolacek at gcc dot gnu.org

--- Comment #8 from Marek Polacek  ---
One thing we should do is to

--- a/gcc/cp/decl.c
+++ b/gcc/cp/decl.c
@@ -12643,7 +12643,7 @@ grokparms (tree parmlist, tree *parms)
  if (deprecated_state != DEPRECATED_SUPPRESS)
{
  tree deptype = type_is_deprecated (type);
- if (deptype)
+ if (deptype && !TYPE_BEING_DEFINED (deptype))
warn_deprecated_use (deptype, NULL_TREE);
}


i.e. don't warn if the deprecated type is being defined.  For the out of class
definition like
void D::f(const D&) { }
it'd be nice if we could somehow walk the qualifying scopes and if DEPTYPE
here:
12643   if (deprecated_state != DEPRECATED_SUPPRESS)
12644 {
12645   tree deptype = type_is_deprecated (type);
12646   if (deptype && !TYPE_BEING_DEFINED (deptype))
12647 warn_deprecated_use (deptype, NULL_TREE);
12648 }
is the same as one of the scopes, don't warn.

[Bug c++/79078] Warnings from deprecated attribute are too noisy

2017-01-13 Thread egall at gwmail dot gwu.edu
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=79078

Eric Gallager  changed:

   What|Removed |Added

 CC||egall at gwmail dot gwu.edu

--- Comment #7 from Eric Gallager  ---
Another way to make deprecation warnings less noisy would be to split
-Wdeprecated-declarations into separate individually controllable flags, for
example, one that only warns about where the "deprecated" attribute is used
with the optional string following it. It could be called
-Wdeprecated-declarations-with-reasons or something, and then it'd make it
easier just to focus on the deprecated things for which there are replacements.
Another way to split it up would be by whether it's deprecated with the
C++-style attribute [-Wc++-deprecated-declarations] or a GNU-style attribute
[-Wgnu-deprecated-declarations]. Just focusing on one or the other might be
easier than trying to deal with warnings from each at the same time. Then
there's also splitting it by the kind of declaration, similar to how -Wunused
is an umbrella warning for several other more specific flags.

[Bug c++/79078] Warnings from deprecated attribute are too noisy

2017-01-13 Thread msebor at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=79078

Martin Sebor  changed:

   What|Removed |Added

 CC||msebor at gcc dot gnu.org

--- Comment #6 from Martin Sebor  ---
This also affects C (and possibly Objective C/C++).  Not sure what Component
might cover both (or all) or if they each need their own bug.

$ cat t.c && gcc -S t.c
struct __attribute__ ((deprecated ("D is bad mmmkay"))) D { };

struct D d1, d2;
t.c:3:8: warning: ‘D’ is deprecated: D is bad mmmkay
[-Wdeprecated-declarations]
 struct D d1, d2;
^
t.c:1:57: note: declared here
 struct __attribute__ ((deprecated ("D is bad mmmkay"))) D { };
 ^
t.c:3:8: warning: ‘D’ is deprecated: D is bad mmmkay
[-Wdeprecated-declarations]
 struct D d1, d2;
^
t.c:1:57: note: declared here
 struct __attribute__ ((deprecated ("D is bad mmmkay"))) D { };
 ^

[Bug c++/79078] Warnings from deprecated attribute are too noisy

2017-01-12 Thread redi at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=79078

--- Comment #5 from Jonathan Wakely  ---
Clang and EDG both procuce two warnings for this code, on the variable
definition and the call to operator+

struct [[deprecated("D is bad mmmkay")]] D {
  void f(const D&);
};

void D::f(const D&) { }

[[deprecated("D is bad ")]] D operator+(const D&, const D&);

int main()
{
  D d; // warning
  d.f(d);
  d + d;   // warning
}

GCC produces seven warnings (and three notes)

d.cc:2:18: warning: ‘D’ is deprecated [-Wdeprecated-declarations]
   void f(const D&);
  ^
d.cc:5:19: warning: ‘D’ is deprecated [-Wdeprecated-declarations]
 void D::f(const D&) { }
   ^
d.cc:7:59: warning: ‘D’ is deprecated: D is bad mmmkay
[-Wdeprecated-declarations]
 [[deprecated("D is bad ")]] D operator+(const D&, const D&);
   ^
d.cc:1:42: note: declared here
 struct [[deprecated("D is bad mmmkay")]] D {
  ^
d.cc:7:59: warning: ‘D’ is deprecated [-Wdeprecated-declarations]
 [[deprecated("D is bad ")]] D operator+(const D&, const D&);
   ^
d.cc:7:59: warning: ‘D’ is deprecated [-Wdeprecated-declarations]
d.cc: In function ‘int main()’:
d.cc:11:5: warning: ‘D’ is deprecated: D is bad mmmkay
[-Wdeprecated-declarations]
   D d;
 ^
d.cc:1:42: note: declared here
 struct [[deprecated("D is bad mmmkay")]] D {
  ^
d.cc:13:7: warning: ‘D operator+(const D&, const D&)’ is deprecated: D is bad 
[-Wdeprecated-declarations]
   d + d;
   ^
d.cc:7:31: note: declared here
 [[deprecated("D is bad ")]] D operator+(const D&, const D&);
   ^~~~

[Bug c++/79078] Warnings from deprecated attribute are too noisy

2017-01-12 Thread redi at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=79078

--- Comment #4 from Jonathan Wakely  ---
Yet another heuristic would be to suppress warnings if the deprecated
attributes have the same string literal in the attribute-argument-clause, i.e.
treat the string as a grouping mechanism, so that entities in a group don't
produce warnings for uses of other deprecated names in the same group.

[Bug c++/79078] Warnings from deprecated attribute are too noisy

2017-01-12 Thread redi at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=79078

Jonathan Wakely  changed:

   What|Removed |Added

 Status|UNCONFIRMED |NEW
   Last reconfirmed||2017-01-13
 Ever confirmed|0   |1

--- Comment #3 from Jonathan Wakely  ---
And then if we dare to define a non-member function that's part  of the
deprecated class' API we end up with five warnings:

struct [[deprecated("D is bad mmmkay")]] D {
  void f(const D&);
};

void D::f(const D&) { }

D operator+(const D&, const D&);

d.cc:2:18: warning: ‘D’ is deprecated [-Wdeprecated-declarations]
   void f(const D&);
  ^
d.cc:5:19: warning: ‘D’ is deprecated [-Wdeprecated-declarations]
 void D::f(const D&) { }
   ^
d.cc:7:31: warning: ‘D’ is deprecated: D is bad mmmkay
[-Wdeprecated-declarations]
 D operator+(const D&, const D&);
   ^
d.cc:1:42: note: declared here
 struct [[deprecated("D is bad mmmkay")]] D {
  ^
d.cc:7:31: warning: ‘D’ is deprecated [-Wdeprecated-declarations]
 D operator+(const D&, const D&);
   ^
d.cc:7:31: warning: ‘D’ is deprecated [-Wdeprecated-declarations]

Again, one is probably enough. The operator uses D, but giving the same warning
three times is unhelpful.

Clang gives three warnings here too, but it's smart enough to not warn if the
function that refers to D is also deprecated. In that case presumably it's part
of the same API, and like the member function case it must be possible for
entities within a "module" to refer to each other even if they are deprecated.
Otherwise writing the module becomes a pain due to all the warnings.

Clang issues no warnings at all for this code:

struct [[deprecated("D is bad mmmkay")]] D {
  void f(const D&);
};

void D::f(const D&) { }

[[deprecated("D is bad ")]] D operator+(const D&, const D&);

GCC gives:

d.cc:2:18: warning: ‘D’ is deprecated [-Wdeprecated-declarations]
   void f(const D&);
  ^
d.cc:5:19: warning: ‘D’ is deprecated [-Wdeprecated-declarations]
 void D::f(const D&) { }
   ^
d.cc:7:59: warning: ‘D’ is deprecated: D is bad mmmkay
[-Wdeprecated-declarations]
 [[deprecated("D is bad ")]] D operator+(const D&, const D&);
   ^
d.cc:1:42: note: declared here
 struct [[deprecated("D is bad mmmkay")]] D {
  ^
d.cc:7:59: warning: ‘D’ is deprecated [-Wdeprecated-declarations]
 [[deprecated("D is bad ")]] D operator+(const D&, const D&);
   ^
d.cc:7:59: warning: ‘D’ is deprecated [-Wdeprecated-declarations]


Another possible heuristic would be to suppress deprecated warnings for
declarations in the same header. A function declared in the same header as D is
probably part of the same API. Warn about uses outside that header, but not
within it. But simply suppressing warnings for functions marked deprecated is
probably good enough.

[Bug c++/79078] Warnings from deprecated attribute are too noisy

2017-01-12 Thread redi at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=79078

--- Comment #2 from Jonathan Wakely  ---
Then we get _another_ warning on the definition of that member function:

struct [[deprecated("D is bad mmmkay")]] D {
  void f(const D&);
};

void D::f(const D&) { }


d.cc:2:18: warning: ‘D’ is deprecated [-Wdeprecated-declarations]
   void f(const D&);
  ^
d.cc:5:19: warning: ‘D’ is deprecated [-Wdeprecated-declarations]
 void D::f(const D&) { }
   ^

[Bug c++/79078] Warnings from deprecated attribute are too noisy

2017-01-12 Thread redi at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=79078

--- Comment #1 from Jonathan Wakely  ---
This warns about the use of D within its own class body:

struct [[deprecated("D is bad mmmkay")]] D {
  void f(const D&);
};

d.cc:2:18: warning: ‘D’ is deprecated [-Wdeprecated-declarations]
   void f(const D&);
  ^

Surely member functions of a deprecated class should be able to refer to the
class, otherwise you can't even implement the API without warnings. And even if
users don't use the class, simply including the header will warn, because the
class refers to itself.