How do I deprecate a class?
Thimo.Neubauer@cst.com
Thimo.Neubauer@cst.com
Wed Mar 21 13:59:00 GMT 2007
Hi!
I'd like to mark a class as deprecated, i.e. any instantiation or method
call should be warned. After reading
http://gcc.gnu.org/onlinedocs/gcc-4.1.2/gcc/Type-Attributes.html#Type-Attributes
I concluded that
class Foo {
public:
void bar(int x);
} __attribute__ ((deprecated));
should do the trick. However
int main() {
Foo f;
return 0;
};
only warns about the (obviously) unused variable but nothing else:
beachboys++ /tmp> make
g++ -Wall foo.cc -o foo
foo.cc: In function int main():
foo.cc:11: warning: unused variable f
beachboys++ /tmp> g++ --version
g++ (GCC) 4.1.2 20061115 (prerelease) (Debian 4.1.1-21)
Copyright (C) 2006 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is
NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE.
Same effect with gcc 3.3 and 3.4. However a
typedef Foo Quux __attribute__ ((deprecated));
with
int main() {
Quux f;
return 0;
};
does what I expected:
foo.cc: In function `int main()':
foo.cc:11: warning: `Quux' is deprecated (declared at foo.cc:8)
foo.cc:11: warning: unused variable `Quux f'
Did I understand anything wrong? Or is this a bug/feature? :-)
Please CC me on reply, I'm not subscribed to gcc-help.
Cheers
Thimo
More information about the Gcc-help
mailing list