Be less ugly when hiding warnings for using the %B formatter

- Take advantage of the new _Pragma operator to hide the printf warning
  suppression inside of macros instead of needing to litter the code
  around Printfs with a bunch of junk.
This commit is contained in:
Randy Heit 2014-12-26 18:58:59 -06:00
parent bce7d12379
commit f76d137d33
3 changed files with 22 additions and 15 deletions

View file

@ -968,10 +968,12 @@ CCMD (dump3df)
fixed_t height=ffloors[i]->top.plane->ZatPoint(CenterSpot(sector));
fixed_t bheight=ffloors[i]->bottom.plane->ZatPoint(CenterSpot(sector));
IGNORE_FORMAT_PRE
Printf("FFloor %d @ top = %f (model = %d), bottom = %f (model = %d), flags = %B, alpha = %d %s %s\n",
i, height / 65536., ffloors[i]->top.model->sectornum,
bheight / 65536., ffloors[i]->bottom.model->sectornum,
ffloors[i]->flags, ffloors[i]->alpha, (ffloors[i]->flags&FF_EXISTS)? "Exists":"", (ffloors[i]->flags&FF_DYNAMIC)? "Dynamic":"");
IGNORE_FORMAT_POST
}
}
}

View file

@ -7496,22 +7496,9 @@ scriptwait:
break;
case PCD_PRINTBINARY:
#if (defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && (__GNUC_MINOR__ >= 6)))) || defined(__clang__)
#define HAS_DIAGNOSTIC_PRAGMA
#endif
#ifdef HAS_DIAGNOSTIC_PRAGMA
#pragma GCC diagnostic push
#ifdef __clang__
#pragma GCC diagnostic ignored "-Wformat-invalid-specifier"
#else
#pragma GCC diagnostic ignored "-Wformat="
#endif
#pragma GCC diagnostic ignored "-Wformat-extra-args"
#endif
IGNORE_FORMAT_PRE
work.AppendFormat ("%B", STACK(1));
#ifdef HAS_DIAGNOSTIC_PRAGMA
#pragma GCC diagnostic pop
#endif
IGNORE_FORMAT_POST
--sp;
break;

View file

@ -47,6 +47,24 @@
#define PRINTFISH(x)
#endif
#ifdef __clang__
#define IGNORE_FORMAT_PRE \
_Pragma("GCC diagnostic push" \
_Pragma("GCC diagnostic ignored \"-Wformat-invalid-specifier\"") \
_Pragma("GCC diagnostic ignored \"-Wformat-extra-args\"")
#define IGNORE_FORMAT_POST _Pragma("GCC diagnostic pop")
#elif defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && (__GNUC_MINOR__ >= 6)))
#define IGNORE_FORMAT_PRE \
_Pragma("GCC diagnostic push" \
_Pragma("GCC diagnostic ignored \"-Wformat=\"") \
_Pragma("GCC diagnostic ignored \"-Wformat-extra-args\"")
#define IGNORE_FORMAT_POST _Pragma("GCC diagnostic pop")
#else
#define IGNORE_FORMAT_PRE
#define IGNORE_FORMAT_POST
#endif
struct FStringData
{
unsigned int Len; // Length of string, excluding terminating null