using g++, how to deprecate virtual class member functions

I seem to be having trouble getting deprecated warnings to print out, for functions declared as virtual. I'm using "g++ (GCC) 4.1.1 20061011 (Red Hat 4.1.1-30)." My research shows that there might be problems in gcc 4.x regarding deprecating pure virtual functions(i.e. class bueller{ virtual int cameron()=0;};), but not... I'd guess you'd call them regular... virtual functions. Just so we're on the same page...

foo.h

class Foo
{
  void Foo_A() __attribute__((deprecated)); //non-virtual
  virtual void Foo_B() __attribute__((deprecated)); //virtual
  virtual void Foo_C() __attribute__((deprecated)) = 0; //pure virtual
};

Say I compiled this, an foo.cpp file and some main.cpp file using g++.

1)Anything that uses Foo_A() will indeed show a warning.

2)Anything that uses Foo_B() does NOT show a warning.

3)Anything that inherits Foo, implements Foo_C and then uses it does not show warning.

Number 1: it works, no problem.

Number 3: seems like a known bug/feature.. whatever..

There seems to be no explination for #2 however. Perhaps it's tied up in #3, although nothing I've found makes mention of it.

Anyone know if I'm missing anything here regarding regular virtual class member functions that I want to deprecate?

BTW: -Wno-deprecate is NOT turned on in my makefiles.

Answers


Given this program:

struct Foo
{
  virtual void Foo_B() __attribute__((deprecated)); //virtual
};

struct DerivedFoo : public Foo
{
};


int main()
{
  DerivedFoo d;
  d.Foo_B();
  Foo &f = d;
  f.Foo_B();
}
void Foo::Foo_B() {}

On CentOS 5.2 (gcc version 4.1.2 20080704 (Red Hat 4.1.2-44)), I get the same output that you describe:

g++     deprecate.cc   -o deprecate
deprecate.cc: In function ‘int main()’:
deprecate.cc:14: warning: ‘Foo_B’ is deprecated (declared at deprecate.cc:3)

But, on Ubuntu 10.04.1 (gcc version 4.4.3 (Ubuntu 4.4.3-4ubuntu5)), I get the output that you expect:

g++     deprecate.cc   -o deprecate
deprecate.cc: In function ‘int main()’:
deprecate.cc:14: warning: ‘virtual void Foo::Foo_B()’ is deprecated (declared at deprecate.cc:3)
deprecate.cc:16: warning: ‘virtual void Foo::Foo_B()’ is deprecated (declared at deprecate.cc:3)

So, I'm guessing it was a compiler bug that got fixed.


Need Your Help

Get Full Mac OS version including revision in PHP

php osx operating-system revision

OK I have looked everywhere and cant find this one out.

Caching images in a Microsoft Excel workbook

c# excel

I have a Microsoft Excel 2013 Workbook project using Microsoft Visual Studio Tools for Office (VSTO) where I would like to have a mechanism for caching an image using a PictureBox. I have the caching

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.