We allow to programmer to add a TODO
message to code. Every time the file is compiled, message is written to the output (via pragma message). The TODO
is a macro, containing a message and date when it was created. E.g. TODO(3, 8, 2015, "...");
I want to validate that no TODO
is older than 30 days (roughly) and prevent compilation if there is such. (you can of course change date, but it will be clearly visible in version control)
I need solution, which works in MS VC 2012
I have written (based on other question) a version, which works fine on gcc - Here is working example
but it doesn't compile on visual studio with error C2057 : expected constant expression
message
#define TOTAL_DAYS(day,month,year) (day + month*31 + year*365)
namespace checkingDate
{
#define C(i) static const char c##i = __DATE__[i];
C(0); C(1); C(2); C(3);
C(4); C(5); C(6); C(7);
C(8); C(9); C(10);
static const int current_date = c4 == ' ' ? c5 - '0' : c5 - '0' + 10;
static const int current_month = (
c0 == 'J' // Jan Jun Jul
? (c1 == 'a' ? 1 : (c2 == 'n' ? 6 : 7))
: c0 == 'F' ? 2
: c0 == 'M' // Mar May
? (c2 == 'r' ? 3 : 5)
: c0 == 'A' // Apr Aug
? (c1 == 'p' ? 4 : 8)
: c0 == 'S' ? 9
: c0 == 'O' ? 10
: c0 == 'N' ? 11
: 12
);
static const int current_year = ((c7 - '0') * 1000) + ((c8 - '0') * 100) + ((c9 - '0') * 10) + (c10 - '0');
static const int totalDays = TOTAL_DAYS(current_date, current_month, current_year);
}
# define TODO(day,month,year, str) static_assert(checkingDate::totalDays - TOTAL_DAYS(day,month,year)<30, "old msg");
int main()
{
TODO(3, 8, 2015, "...");
}
Can I somehow fix this error? Is it my error or MS VC bug? Is there other way to write it, so it works in visual studio?