Opened 5 years ago

Last modified 5 years ago

#136 new enhancement

PtrsAssignable Rework

Reported by: ajbeach Owned by:
Priority: major Component: cfa-cc
Version: 1.0 Keywords:
Cc:

Description

The visitor used to implement part of the helper function is almost entirely boiler plate. It never recurses (not even manually) and most of the functions don't do anything.

The entire thing should be easy to replace with a pair of if statements which check for a successful dynamic_cast. The bodies of the if statements being the bodies of the few postvisit functions that actually do anything.

Change History (3)

comment:1 Changed 5 years ago by Rob Schluntz

Definitely verify this, but if memory serves then this does not recurse for a reason. I think it's the case that you don't want to be able to directly assign multilevel pointers of different types, which would be allowed for void * and T *. For example:

$ cat test.c
int main() {
  void * v, ** vv;
  int * i, **ii;
  v = i;
  vv = ii;
}
$ gcc test.c
test.c:5:6: warning: incompatible pointer types assigning to 'void **' from 'int **' [-Wincompatible-pointer-types]
  vv = ii;
     ^ ~~
1 warning generated.

I'm fairly certain this is the case that's being handled by not recursing here (well, general argument passing, not just assignment, despite the name).

comment:2 Changed 5 years ago by a3moss

I think the suggestion was to replace the visitor with a function of the following form, rather than change the semantics:

if ( auto foo = dynamic_cast< Foo * >( x ) ) {
  // do stuff
} else if ( auto bar = dynamic_cast< Bar * >( x ) ) {
  // do other stuff
}

comment:3 Changed 5 years ago by Rob Schluntz

Ahhh, okay I understand now. Sounds good to me :)

Note: See TracTickets for help on using tickets.