support non-standard declaration features like __declspec, __attribute__, verbatim
Contract Programming Library for C++
Status: Pre-Alpha
Brought to you by:
lcaminiti
did not think of anything else. But now, that I think of it, I wonder how
vendor-speciffic extensions are (or could be) supported, like Microsoft's
declspec? While they are not C++-standard I must use them when
implementing a DLL.
I can't support all compiler extension--where would I stop?? But I can and probably should support a few that very often used at least for MSVC and G++.
CONTRACT_CLASS(
verbatim(declspec(dllimport)) class (x)
) {
CONTRACT_CLASS_INVARIANT( void )
} varx;
CONTRACT_CLASS(
class verbatim(declspec(dllimport)) (x)
) {
CONTRACT_CLASS_INVARIANT( void )
};
If possible, this could be used to support a number of different
(all?) compiler extensions because the lib doesn't need to know
anything about the content of a verbatim clasule but just that the
specified tokens have to be repeated "in place and as they are" when
expanding the macros.
One difficulty with this is defining
exactly what "in place" means. You'll
need to specify how locations in your
syntax map to locations in the C++
declaration in all the places where
the syntax is different. e.g.
void (f)(int i, verbatim(extension) default 10)
a) void f(int i extension = 1)
b) void f(int i = extension 1)
c) This is illegal
CONTRACT_CLASS(
declspec(dllimport) class (x)
) {
CONTRACT_CLASS_INVARIANT( void )
} varx;
CONTRACT_CLASS(
class declspec(dllimport) (x)
) {
CONTRACT_CLASS_INVARIANT( void )
};
What do you think?
I think both are good. You should implement
important known compiler extensions like
declspec and attribute directly and
also provide verbatim to handle unknown
or future compiler extensions.
I think it's a keyword and not defined as a macro but that can't be
guaranteed given that compilers are free to implement it as they wish.
Maybe I should use declspec and attribute (no ) for those while
verbatim will accept any as the compiler defines them.