This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c++/16370] New: __attribute__((deprecated)) not useful on classes, and ugly function name listed for deperecation warnings on constructor


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.

-- 
           Summary: __attribute__((deprecated)) not useful on classes, and
                    ugly function name listed for deperecation warnings on
                    constructor
           Product: gcc
           Version: 3.4.0
            Status: UNCONFIRMED
          Severity: minor
          Priority: P2
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: tim dot vanholder at anubex dot com
                CC: gcc-bugs at gcc dot gnu dot org
 GCC build triplet: i686-pc-linux-gnu
  GCC host triplet: i686-pc-linux-gnu
GCC target triplet: i686-pc-linux-gnu


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=16370


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]