ID:1558161
 
Keywords: macro, preprocessor, wtf
Applies to:DM Language
Status: Open

Issue hasn't been assigned a status value.
The DM pre-processor refuses to perform a wide variety of ridiculous substitutions, but either doesn't indicate this with compile errors (most common), or throws strange errors that don't appear remotely related to the bad directive.
Here are a few examples:

#define del(X) new X.type(X)
#define del(X) anything

#define #undef #define
#undef #define
#define #warn #error
#define #error #warn

#define something #define
#define something #undef

Either of the following would be helpful:

A: Throw a compile error whenever a pre-processor directive cannot be executed (or fails a sanity check), eg:

error: unreasonable macro definition (programmer intoxicated?)

B: Allow these sorts of definitions. What's the worst that could happen?

P.S. The DMpp will happily #define __FILE__, __LINE__, and/or __MAIN__. Maybe this should trigger a warning?
"#define u #define" is actually one I've used in 4K projects. The fact that DM allows it has been exploited in existing code.

I don't actually see anything problematic about any of the above. What would be the point in limiting the preprocessor's functionality rather than expanding it?

As far as the risk of strange errors, chalk that up to the ordinary risk any programmer takes on when they try to take the reins at such a low level.
Makes sense. In that case, it's fine how it is.