c++/6365: Uninitialized static pointer-to-member is not NULL(-1)

jessica_han@hp.com jessica_han@hp.com
Thu Apr 18 12:16:00 GMT 2002


>Number:         6365
>Category:       c++
>Synopsis:       Uninitialized static pointer-to-member is not NULL(-1)
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Thu Apr 18 12:16:01 PDT 2002
>Closed-Date:
>Last-Modified:
>Originator:     jessica_han@hp.com
>Release:        gcc version 3.1 20020415 (prerelease)
>Organization:
>Environment:
IA64 Linux & HP-UX
>Description:
Uninitialized static pointer-to-member is set to NULL by default.
IA64 C++ ABI specifies that a NULL pointer-to-member should
be -1.
>How-To-Repeat:
#g++ test4.C
#./a.out
#echo $?
1 (should be 0)
>Fix:

>Release-Note:
>Audit-Trail:
>Unformatted:
----gnatsweb-attachment----
Content-Type: text/plain; name="test4.C"
Content-Disposition: inline; filename="test4.C"

#include <stdio.h>
// The subject.
struct A
{
  int i;
};

int A::* gp;
int A::* ga[2];

// Test use in a simple struct.
struct B
{
  int A::* mp;
};

B gb;

// Test that in a class with a constructor, the pointer to member is
// zero-initialized until the constructor is run.
struct C
{
  C (): mp (&A::i) {}
  int A::* mp;
};

extern C gc;
int fail;
struct D
{
  D ()
  {
    if (gc.mp != 0)
      fail = 4;
  }
};

// The D must come first for this to work.
D gd;
C gc;

int main()
{
  static int A::* slp;
  static int A::* sla[2];
  static B slb;

  if (gp != 0 || slp != 0)
    return 1;
  if (ga[1] != 0 || sla[1] != 0)
    return 2;
  if (gb.mp != 0 || slb.mp != 0)
    return 3;
  return fail;
}



More information about the Gcc-prs mailing list