D - code prover interface (new type of static assert?)
- Daniel Horn (29/29) Apr 27 2004 Apologies for having not carefully read the august const flamewars
Apologies for having not carefully read the august const flamewars
It appears that the people who like const, want the compiler to prove
that their own code does not modify certain numbers of their own variables.
And the people who don't like const say that it mucks up the interface
and other libs may violate their const contracts, so it's useless.
All I want the compiler to do is to traverse MY code seeing if the
variable in question is modified, and let me know of potentially
offending lib calls that it cannot verify.
Perhaps this harkens back to the static_assert feature...
if I could just ASSERT that this data was not modified as far as the
compiler knows (perhaps warnings if it can't get the source of a lib
that may modify it)then I would be happy.
it would be something like
x = new MyClass;
y = new MyClass;
const_assert(x.memberVar,y) {
int z= myFunc(x,y); // <-- some benign function
x.memberVar+=5; // compiler asserts here.
}
this probably opens up a new can of worms, but my idea is that it would
apply to very small code-snippits like code that is currently
destructive and needs to be upgraded to non-destructive.
And it would warn in the absence of source code.
Since D is a CFG someone could probably write some bison or yacc script
to do this, yes?
And could call it D++? :-P
in C++ you could accomplish this feature by shadowing the variable in
question with const &thatVariable=thatVariable instead
--Daniel
Apr 27 2004








Daniel Horn <hellcatv hotmail.com>