Bug 16370 - __attribute__((deprecated)) not useful on classes, and ugly function name listed for deperecation warnings on constructor
Summary: __attribute__((deprecated)) not useful on classes, and ugly function name lis...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 3.4.0
: P2 normal
Target Milestone: ---
Assignee: Jason Merrill
URL:
Keywords: diagnostic
Depends on:
Blocks:
 
Reported: 2004-07-05 13:44 UTC by Tim Van Holder
Modified: 2007-09-23 15:28 UTC (History)
4 users (show)

See Also:
Host: i686-pc-linux-gnu
Target: i686-pc-linux-gnu
Build: i686-pc-linux-gnu
Known to work:
Known to fail:
Last reconfirmed: 2007-09-23 15:28:24


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Tim Van Holder 2004-07-05 13:44:55 UTC
When __attribute__((deprecated)) is applied to a class, gcc only warns when the
class name is used in a typedef, not when the class is instantiated or if static
class members are referenced.  This makes the attribute of limited use for
classes, requiring adding the attribute to every member as well.
On constructors, the warning that is given uses an uglified function name.

Simple test case:

class foo {
public:
  static const int something;
} __attribute__((deprecated));

typedef class foo FOO; // warns like it should

class foo2 {
  int value_;
public:
  foo2(void);
  foo2(int) __attribute__((deprecated));
  void bar(void) __attribute__((deprecated));
};

foo2::foo2(void) : value_(0) { }

foo2::foo2(int v) : value_(v) { }

void
foo2::bar(void)
{
  this->value_ += 42;
}

void
xyzzy(void)
{
  foo test1; // should warn, but doesn't
  foo* test2 = new foo; // should warn, but doesn't
  delete test2;
  FOO test3; // no warning, but that's ok, the typedef shows warning
  int test4 = foo::something; // should warn, but doesn't
  foo2 test5;
  test5.bar(); // warns like it should
  foo2 test6(foo::something); // should warn twice, but only warns once and
                              // uses ugly method name (__comp_ctor)
}

int
main(void)
{
  xyzzy();
  return 0;
}

Resulting output:

xxx.cc:6: warning: `foo' is deprecated (declared at xxx.cc:1)
xxx.cc: In function `void xyzzy()':
xxx.cc:35: warning: `bar' is deprecated (declared at xxx.cc:22)
xxx.cc:36: warning: `__comp_ctor' is deprecated (declared at xxx.cc:18)

Note that errors also refer to the last seen declaration or definition, and not
the declaration - but there already is a bug report for that.
Comment 1 Andrew Pinski 2004-08-02 01:14:37 UTC
Confirmed.  Sounds like GCC is using the DECL_NAME instead of (I cannot remember the name right 
now).
Comment 2 Andrew Pinski 2005-05-01 03:41:47 UTC
We now get:
t.cc:36: warning: ‘__comp_ctor ’ is deprecated (declared at t.cc:18)

note the extra space.
Comment 3 Gabriel Dos Reis 2005-05-01 05:21:38 UTC
Subject: Re:  __attribute__((deprecated)) not useful on classes, and ugly function name listed for deperecation warnings on constructor

"pinskia at gcc dot gnu dot org" <gcc-bugzilla@gcc.gnu.org> writes:

| ------- Additional Comments From pinskia at gcc dot gnu dot org  2005-05-01 03:41 -------
| We now get:
| t.cc:36: warning: __comp_ctor  is deprecated (declared at t.cc:18)
| 
| note the extra space.

The extra space is part of the name, if you ask me.

-- Gaby
Comment 4 Ian Lance Taylor 2007-03-21 14:39:14 UTC
With current mainline, I get no warning for this:

struct Foo { int i; } __attribute__ ((deprecated));
void foo() { Foo f; }

but I do get a warning for this:

struct Foo { int i; } __attribute__ ((deprecated));
void foo() { struct Foo f; }

The only different is the "struct" keyword.  That is bizarre.
Comment 5 Benjamin Kosnik 2007-05-17 17:22:12 UTC
Also an issue with class templates.

See this thread:
http://gcc.gnu.org/ml/libstdc++/2007-05/msg00113.html

I'm changing this to normal severity, since we absolutely need a solution pronto on this, as it is essential for C++0x work.
Comment 6 Jason Merrill 2007-09-23 15:27:21 UTC
Subject: Bug 16370

Author: jason
Date: Sun Sep 23 15:27:10 2007
New Revision: 128691

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=128691
Log:
        PR c++/16370
        * decl.c (grokdeclarator): Look through implicit TYPE_DECLs
        for deprecation warnings.

Added:
    trunk/gcc/testsuite/g++.dg/warn/deprecated-5.C
Modified:
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/decl.c
    trunk/gcc/testsuite/g++.dg/warn/deprecated.C

Comment 7 Jason Merrill 2007-09-23 15:28:41 UTC
Fixed for 4.3.0.