[Bug c++/21980] New: syntax error with static function pointer (compiler dependent)

2005-06-09 Thread nkoch at demig dot de
Take this c++ code:

 snip 
class Test
{
  private:
int val;
static Test func1 ();
static Test func2 ();
static Test (* funcp) ();

  public:
Test (int val)
  : val (val)
{
}

Test func ()
{
  return funcp ();
}

int get () const
{
  return val;
}
};

Test (* Test::funcp) () = Test::func1;

Test Test::func1 ()
{
  funcp = func2;
  return Test (1);
}

Test Test::func2 ()
{
  return Test (2);
}
 snip 

The code above compiles w/o errors under 3.4.5 and produces these
errors under 3.3.6:

bug33.cpp:7: error: parse error before `*' token
bug33.cpp: In member function `Test Test::func()':
bug33.cpp:17: error: `funcp' undeclared (first use this function)
bug33.cpp:17: error: (Each undeclared identifier is reported only once for each 
   function it appears in.)
bug33.cpp: At global scope:
bug33.cpp:26: error: `Test (*Test::funcp)()' is not a static member of `class 
   Test'

Which of the compilers is right? Are static function pointers to
static class functions legal c++ code? Is the declaration syntax
standard conforming?

-- 
   Summary: syntax error with static function pointer (compiler
dependent)
   Product: gcc
   Version: 3.3.6
Status: UNCONFIRMED
  Severity: normal
  Priority: P2
 Component: c++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: nkoch at demig dot de
CC: gcc-bugs at gcc dot gnu dot org
 GCC build triplet: i386-portbld-freebsd4.11
  GCC host triplet: i386-portbld-freebsd4.11
GCC target triplet: i386-portbld-freebsd4.11


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


[Bug c++/20316] New: attribute((packed)) and call by reference

2005-03-04 Thread nkoch at demig dot de
I have this test program:

struct P { char a; int b; } __attribute__ ((__packed__));

int f (char  i) { return ++ i; }
int f (int   i) { return ++ i; }
int f (char * i) { return ++ * i; }
int f (int  * i) { return ++ * i; }

int main ()
{
  P x;
  x.a = 1;
  x.b = 1;
  int i = f (x.a) + f (x.b) + f ( x.a) + f ( x.b);
  return 0;
}


It compiles with gcc3.3 (gcc version 3.3.6 20050223 (prerelease) [FreeBSD])
but not with gcc.3.4 (gcc version 3.4.4 20050211 (prerelease) [FreeBSD]).

GCC reports:
test.cpp: In function `int main()':
test.cpp:13: error: cannot bind packed field `x.P::a' to `char'
test.cpp:13: error: cannot bind packed field `x.P::b' to `int'

Probably, this is not a bug but a feature, but what can I do
to my program, which needs a lot of packed structures and runs fine
with gcc3.3?
Perhaps I have to cast away the packed attribute somehow ??
I understand, that my code may not work on cpus needing some specific
alignment, but where is the problem with char? And if this is a cpu issue,
why do the pointers work, but _not_ the references?

-- 
   Summary: attribute((packed)) and call by reference
   Product: gcc
   Version: 3.4.4
Status: UNCONFIRMED
  Severity: normal
  Priority: P2
 Component: c++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: nkoch at demig dot de
CC: gcc-bugs at gcc dot gnu dot org
 GCC build triplet: i386-portbld-freebsd4.10
  GCC host triplet: i386-portbld-freebsd4.10
GCC target triplet: i386-portbld-freebsd4.10


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