www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [adress op] sudden AV

reply Manfred Nowak <svv1999 hotmail.com> writes:
All asserts should path, but do not:

<code>
class C{
  void f(){};

  void opCall(){
    assert( &f);
    printf("assert 2 passed.\n");
  }
  
  struct S{
    void opCall(){
      assert( &f);
      printf("assert 3 passed.\n");
    }
  } S s;
}
void main(){
  
  C c= new C;

  assert( &(c.f));
  printf("assert 1 passed.\n");
  c();
  c.s();
 
}
</code>
Apr 22 2005
next sibling parent Nick <Nick_member pathlink.com> writes:
In article <d4apqu$2bo2$1 digitaldaemon.com>, Manfred Nowak says...
All asserts should path, but do not:

<code>
class C{
  void f(){};

  void opCall(){
    assert( &f);
    printf("assert 2 passed.\n");
  }
  
  struct S{
    void opCall(){
      assert( &f);
      printf("assert 3 passed.\n");
    }
  } S s;
}
[...]

This is not supposed to work, since the struct S has no link to any instance of the class C, and hence no pointer to the function f (f is a virtual function, so without a class instance you have no pointer.) In fact it shouldn't even compile, since f isn't well defined in S. Nick
Apr 22 2005
prev sibling parent Thomas Kuehne <thomas-dloop kuehne.thisisspam.cn> writes:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Manfred Nowak schrieb am Fri, 22 Apr 2005 12:14:22 +0000 (UTC):
 All asserts should path, but do not:

<code>
 class C{
   void f(){};

   void opCall(){
     assert( &f);
     printf("assert 2 passed.\n");
   }
   
   struct S{
     void opCall(){
       assert( &f);
       printf("assert 3 passed.\n");
     }
   } S s;
 }
 void main(){
   
   C c= new C;

   assert( &(c.f));
   printf("assert 1 passed.\n");
   c();
   c.s();
  
 }
</code>

Added to DStress as http://dstress.kuehne.cn/nocompile/scope_02.d Thomas -----BEGIN PGP SIGNATURE----- iD8DBQFCae7p3w+/yD4P9tIRAqJRAJ4n3D7YtQgNiBTJi+kJy6IsrGnPHgCgjUer G5gVdi3qwHcWwBrg5tK/MdU= =+vxA -----END PGP SIGNATURE-----
Apr 22 2005