public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/101015] New: Poor diagnostic for deprecated alias-declaration
@ 2021-06-10 13:13 redi at gcc dot gnu.org
  2021-06-10 13:44 ` [Bug c++/101015] " mpolacek at gcc dot gnu.org
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: redi at gcc dot gnu.org @ 2021-06-10 13:13 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101015

            Bug ID: 101015
           Summary: Poor diagnostic for deprecated alias-declaration
           Product: gcc
           Version: 12.0
            Status: UNCONFIRMED
          Keywords: diagnostic
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: redi at gcc dot gnu.org
  Target Milestone: ---

struct A {
  typedef int good [[deprecated]];
  using bad [[deprecated]] = int;
};

A::good i = 0;
A::bad j = 0;

This prints:

depr.C:6:9: warning: 'A::good' is deprecated [-Wdeprecated-declarations]
    6 | A::good i = 0;
      |         ^
depr.C:2:15: note: declared here
    2 |   typedef int good [[deprecated]];
      |               ^~~~
depr.C:7:8: warning: 'using bad = int' is deprecated
[-Wdeprecated-declarations]
    7 | A::bad j = 0;
      |        ^
depr.C:3:9: note: declared here
    3 |   using bad [[deprecated]] = int;
      |         ^~~


When it is good it is very very good, but when it is bad it is horrid.

The second warning should print 'A::bad' not 'using bad = int'.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug c++/101015] Poor diagnostic for deprecated alias-declaration
  2021-06-10 13:13 [Bug c++/101015] New: Poor diagnostic for deprecated alias-declaration redi at gcc dot gnu.org
@ 2021-06-10 13:44 ` mpolacek at gcc dot gnu.org
  2021-06-11 15:50 ` mpolacek at gcc dot gnu.org
  2021-07-22  9:47 ` redi at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2021-06-10 13:44 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101015

Marek Polacek <mpolacek at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Last reconfirmed|                            |2021-06-10
                 CC|                            |mpolacek at gcc dot gnu.org
     Ever confirmed|0                           |1
             Status|UNCONFIRMED                 |NEW

--- Comment #1 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Confirmed.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug c++/101015] Poor diagnostic for deprecated alias-declaration
  2021-06-10 13:13 [Bug c++/101015] New: Poor diagnostic for deprecated alias-declaration redi at gcc dot gnu.org
  2021-06-10 13:44 ` [Bug c++/101015] " mpolacek at gcc dot gnu.org
@ 2021-06-11 15:50 ` mpolacek at gcc dot gnu.org
  2021-07-22  9:47 ` redi at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2021-06-11 15:50 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101015

--- Comment #2 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
This is because dump_decl does the decoration for TYPE_DECL_ALIAS_P:

1228       if (TYPE_DECL_ALIAS_P (t)
1229           && (flags & TFF_DECL_SPECIFIERS
1230               || flags & TFF_CLASS_KEY_OR_ENUM))
1231         {
1232           pp_cxx_ws_string (pp, "using");
1233           dump_decl (pp, DECL_NAME (t), flags);
1234           pp_cxx_whitespace (pp);
1235           pp_cxx_ws_string (pp, "=");
1236           pp_cxx_whitespace (pp);
1237           dump_type (pp, (DECL_ORIGINAL_TYPE (t)
1238                           ? DECL_ORIGINAL_TYPE (t) : TREE_TYPE (t)),
1239                      flags);

A way around it would be to disable TYPE_DECL_ALIAS_P temporarily for the
warning:

--- a/gcc/cp/decl2.c
+++ b/gcc/cp/decl2.c
@@ -5519,7 +5519,16 @@ cp_warn_deprecated_use (tree decl, tsubst_flags_t
complain)
    }
     }
   else
-    warned = warn_deprecated_use (decl, NULL_TREE);
+    {
+      // XXX alias_type_or_template_p?
+      const bool using_p = (TREE_CODE (decl) == TYPE_DECL
+               && TYPE_DECL_ALIAS_P (decl));
+      if (using_p)
+   TYPE_DECL_ALIAS_P (decl) = false;
+      warned = warn_deprecated_use (decl, NULL_TREE);
+      if (using_p)
+   TYPE_DECL_ALIAS_P (decl) = true;
+    }

   return warned;
 }

and then we get:

101015.C:7:8: warning: ‘A::bad’ is deprecated [-Wdeprecated-declarations]
    7 | A::bad j = 0;
      |        ^
101015.C:3:9: note: declared here
    3 |   using bad [[deprecated]] = int;
      |         ^~~

But maybe that's too ugly a hack.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug c++/101015] Poor diagnostic for deprecated alias-declaration
  2021-06-10 13:13 [Bug c++/101015] New: Poor diagnostic for deprecated alias-declaration redi at gcc dot gnu.org
  2021-06-10 13:44 ` [Bug c++/101015] " mpolacek at gcc dot gnu.org
  2021-06-11 15:50 ` mpolacek at gcc dot gnu.org
@ 2021-07-22  9:47 ` redi at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: redi at gcc dot gnu.org @ 2021-07-22  9:47 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101015

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           See Also|                            |https://gcc.gnu.org/bugzill
                   |                            |a/show_bug.cgi?id=84360

--- Comment #3 from Jonathan Wakely <redi at gcc dot gnu.org> ---
namespace v2
{
  template<typename T> struct blargle { };
}

namespace v1
{
  template<typename _Tp>
    using blargle [[deprecated("use v2::blargle instead of v1::blargle")]]
      = v2::blargle<_Tp>;
}

v1::blargle<int> a;


da.C:13:18: warning: 'using blargle = struct v2::blargle<int>' is deprecated:
use v2::blargle instead of v1::blargle [-Wdeprecated-declarations]
   13 | v1::blargle<int> a;
      |                  ^
da.C:9:11: note: declared here
    9 |     using blargle [[deprecated("use v2::blargle instead of
v1::blargle")]]
      |           ^~~~~~~


The expanded using-declaration is especially unhelpful when it re-uses the same
name in a different namespace. It would be better to print the type including
its namespace qualification:

warning: 'v1::blargle' is deprecated: ...

Maybe related to PR 84360

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2021-07-22  9:47 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-10 13:13 [Bug c++/101015] New: Poor diagnostic for deprecated alias-declaration redi at gcc dot gnu.org
2021-06-10 13:44 ` [Bug c++/101015] " mpolacek at gcc dot gnu.org
2021-06-11 15:50 ` mpolacek at gcc dot gnu.org
2021-07-22  9:47 ` redi at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).