[cfe-dev] Two style questions

Cédric Venet cedric.venet at student.ecp.fr
Sat Nov 10 11:42:27 PST 2007


Hi,

First, clang didn't seems to use any smart_ptr. Is it by design?
I would like to use a scoped_ptr (for class member or local variable), what
should I do:
- do the freeing manually in the destructor or at the end of the function
(error prone and not maintenable)
- use std::auto_ptr
- use an home made scoped_ptr
- use boost::scoped_ptr (I know you don't want to create dependency on
boost, for simplicity of compilation, but we could extract the few class
needed)


Second, in a few place, typedef of void are used as opaque type (for
reducing dependency or allowing various concrete type depending on the
implementation) and I was wondering why not use empty struct instead:

typedef void ExprTy; => struct ExprTy {};

I can see than a void* is easier to cast (static_cast instead of
reinterpret_cast) but the concrete type could derive from the empty struct
achieving the same without cost (thanks to empty base class optimization).
This would allow stronger type checking and less bug, or is there any reason
I didn't see?

In particular, I don't see why BuilderTy in ModuleBuilder.h is declared as
an opaque type since it represente a CodeGenModule and could simply use a
forward declared class no?

typedef void BuilderTy;

=>

Class CodeGenModule;
typedef CodeGenModule BuilderTy;


Regards,

Cédric

-- 
Cédric Venet







More information about the cfe-dev mailing list