[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#218482: linux-kernel-headers: Some headers seem to expand inline twice



Package: linux-kernel-headers
Version: 2.5.999-test7-bk-5
Severity: normal

The following simple C++ program doesn't compile.  (I presume it's
expected that things like signal.h should be available in C++.)

#include <iostream>
extern "C"
{
#include <signal.h>
}

class Foo
{
public:
  void inline hello ()
  {
    std::cout << "hello\n";
  }
} foo;

int
main ()
{
  foo.hello ();
  exit (0);
}

The error seems to be caused by the inclusion of one or more of these
files:

/usr/include/linux/compiler-gcc.h
/usr/include/linux/compiler-gcc3.h
/usr/include/linux/compiler.h

After preprocessing, the method looks like this:

        void __inline__ __attribute__((always_inline)) __attribute__((always_inline)) hello()
        {
        std::cout << "hello\n";
        }

and g++ reports:

test.C:10: error: declaration does not declare anything
test.C:10: error: parse error before `__attribute__'
test.C:14: error: ISO C++ forbids declaration of `foo' with no type

A workaround is to put the inline first:

  inline void hello ()
  {
    std::cout << "hello\n";
  }

and that seems acceptable (and arguably better style).  

However, my reading of the allowable grammar (it's in Appendix A.6 of
the ANSI standard) suggests that these are all decl-specifiers, and
any ordering ought to be allowed.  (That's not conclusive, since
typedef is in the same list, and I doubt it's intended that "double
typedef ..." is intended to be legal.  But without including signal.h,
g++ accepts either ordering, so that suggests that the intent is to
allow "void inline" as equivalent to "inline void", and that one of
these headers is subverting that.)

-- System Information:
Debian Release: testing/unstable
Architecture: i386
Kernel: Linux tiny 2.6.0-test9-lufs #1 SMP Fri Oct 31 14:06:10 GMT 2003 i686
Locale: LANG=C, LC_CTYPE=C

-- no debconf information




Reply to: