Forward declaration issue on gcc 3.4.3(New)

2006-01-17 Thread Jian-ping . Hui


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



RE: Forward declaration issue on gcc 3.4.3(New)

2006-01-17 Thread Jian-ping . Hui

Hi, Dave,

Thanks a lot for your help.

Best Regards
Jian-ping

-"Dave Korn" <[EMAIL PROTECTED]> wrote: -

To: <[EMAIL PROTECTED]>, 
From: "Dave Korn" <[EMAIL PROTECTED]>
Date: 01/17/2006 07:04PM
cc: <[EMAIL PROTECTED]>
Subject: RE: Forward declaration issue on gcc 3.4.3(New)

Jian-ping.Hui wrote:

> Now my question is: Why there are such difference between the two version
> gcc?

  This is a VFAQ.  See http://gcc.gnu.org/gcc-3.4/changes.html#cplusplus

> Could I compile b.cpp by simply changing some compiler options?

  No, you will have to fix the invalid code to be fully compliant with the
C++
language standard.



cheers,
  DaveK
--
Can't think of a witty .sigline today