If in a .h file you include another file with the same name, but in a different
directory, that contains a #pragma interface, it seems that the #pragma
interface gets extended to the current file, past the end of the included file.

In the following example there are three files:
a.h   : contains the declaration of a class
a.cpp : includes a.h and contains the implementation of the class.
b/a.h : this is included in a.h. It has the same name as a.h, but is in a
different directory. It contains a #pragma interface

When you compile a.cpp, it doesn't create the virtual table for the Test class.
It looks like the '#pragma interface' is extended to a.h, and since it doesn't
find the corresponding '#pragma implementation' it doesn't include the virtual
table for the class in the object file.

Here's the example:

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

Test::Test(){}

void Test::f(){}

$ cat a.h
#include "b/a.h"

class Test
{
    public:
        Test();
        virtual void f();
};

$ cat b/a.h

#pragma interface "a.h"
===

If you compile a.cpp, the virtual table for class Test is not created in the
object file:

$ g++ a.cpp
$ nm -C a.o
00000020 T Test::f()
00000010 T Test::Test()
00000000 T Test::Test()
         U vtable for Test

If you rename the file a.h to a2.h and change a.cpp accordingly, you get:
$ nm -C a.o
00000020 T Test::f()
00000010 T Test::Test()
00000000 T Test::Test()
00000000 V typeinfo for Test
00000000 V typeinfo name for Test
00000000 V vtable for Test
         U vtable for __cxxabiv1::__class_type_info

Which should be the correct behaviour.


I've seen this since 4.0. It wasn't present in 3.3.
I've tested it both with gcc 4.0.1 and with the latest 4.1 cvs snapshot:

$ g++ -v
Using built-in specs.
Target: i686-pc-linux-gnu
Configured with: ../gcc-4.1-20051001/configure --prefix=/home/vbato/gcc41
Thread model: posix
gcc version 4.1.0 20051001 (experimental)


-- 
           Summary: pragma interface in included file with same name
           Product: gcc
           Version: 4.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: vbato dot bugs at gmail dot com


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=24215

Reply via email to