GCC 4.3 Transition

From openSUSE

Contents

Missing Includes

The include dependencies of the standard library headers were cleaned up a lot and a lot less unneeded dependencies are pulled in. This results in errors like

       Geometry.cpp: In member function 'const Magick::Geometry& Magick::Geometry::operator=(const std::string&)':
       Geometry.cpp:191: error: 'strcpy' was not declared in this scope
       make[3]: *** [Geometry.lo] Error 1

which hints at that you should include <cstring>, the C++ standard include name of the C string.h header. The rule of thumb is to look in which C header the missing function is in and then include the C++ variant which has a 'c' prepended and the '.h' stripped off.

This is 90% of all errors we currently see with C++ programs.

Extra Warnings

There are extra warnings with GCC 4.3 and you use -Werror. You simply need to fix them.

More Picky Preprocessor

       main.cpp:182:7: error: extra tokens at end of #endif directive

the preprocessor diagnoses

       #endif foo

use #endif /* foo */ instead.

C99 inline semantics changes

If you use 'extern inline foo(....' in headers and build with either -std=c99 or -std=gnu99 then you will probably face linker errors complaining about duplicate symbols.

If you want to fix this in a way that is compatible with GCC 4.3 and previous versions use something like the following:

       extern inline
       #ifdef __GNU_STDC_INLINE__
       __attribute__((__gnu_inline__))
       #endif
       foo(....

which will preserve the previous semantics. If you do not care about compatibility with older GCC and want to use C99 semantics simply remove the 'extern' qualifier on inline functions defined in headers.

Template Stuff

If you see something like

       /usr/include/zypp/Bit.h:86: error: declaration of 'typedef struct zypp::bit::MaxBits<_IntT> zypp::bit::Range<_IntT, _begin, _size>::MaxBits'
       /usr/include/zypp/Bit.h:52: error: changes meaning of 'MaxBits' from 'struct zypp::bit::MaxBits<_IntT>'

you did something like

       template <class T>
       struct Foo : public FooBar<T> {
               typedef Foo::FooBar<T> FooBar;
               ...

this is invalid C++. Use a different typedef-name here:

               typedef Foo::FooBar<T> FooBar_t;

Another example is:

   template <class _Tp> class auto_ptr {};
   template <class _Tp>
   class counted_ptr
   {
   public:
     auto_ptr<_Tp> auto_ptr();
   };
       t.C:6: error: declaration of 'auto_ptr<_Tp> counted_ptr<_Tp>::auto_ptr()'
       t.C:1: error: changes meaning of 'auto_ptr' from 'class auto_ptr<_Tp>'

where you should simply qualify the reference to auto_ptr in the global namespace.

Undefined References

   filter.cc:(.text+0x15e): undefined reference to `__gnu_cxx::__normal_iterator<...> std::remove_if<...>(...)'

You need to include the header 'algorithm'

   #include <algorithm>