This is the mail archive of the gcc-help@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]

Forward declaration issue on gcc 3.4.3(New)



Sorry for the previous wrong format mail. Please ignore it.

I encountered an issue when building our program. The compilation will fail
when using gcc 3.4.3. However, the same program can be compiled
successfully with gcc 3.2.3.

I used the following example to reproduce the issue:
=====
a.h
=====
#ifndef A_H_
#define A_H_
class A
{
public:
        A() { }
        ~A() { }
        void FuncA();
};
#endif

======
a.cpp
======
#include "a.h"

======
b.h
======
#ifndef B_H_
#define B_H_
class A;
template class B
{
public:
        B() { }
        ~B() { }
        void FuncB()
        {
                A* pa;
                pa->FuncA();
        }
};
#endif

======
b.cpp
======
#include "b.h"
#include "a.h"

I used the following commands to compile b.cpp:
    /usr/bin/g++  -c -g  b.cpp

I got different result when using different version gcc.
    ===================================================
    gcc version 3.2.3 20030502 (Red Hat Linux 3.2.3-42)
    ===================================================
    Success.

    ===================================================
    gcc version 3.4.3 20041212 (Red Hat 3.4.3-9.EL4)
    ===================================================
    Fail with errors as below:
        In file included from b.cpp:1:
        b.h: In member function `void B::FunB()':
        b.h:16: error: invalid use of undefined type `struct A'
        b.h:4: error: forward declaration of `struct A'

If I change the order of head files in b.cpp to:
    #include "a.h"
    #include "b.h"
The compilation will pass.

Now my question is: Why there are such difference between the two version
gcc? Could I compile b.cpp by simply changing some compiler options?
Hopeful for your quick reply. I 'm very appeaciate for your help.

Thanks.

Best Regards
Jianping Hui
2006-01-16


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