Suppress variable shadowing warnings

This disables the warnings for MSVC, GCC and Clang in the ZoneScopedXX
macros.

The warnings produced are both a false positive since they didn't find a
bug *and* they don't happen in user written code, so the user couldn't
even do much about it. The previous workaround of using ZoneNamedXXX is
a poor solution since the Zone(Text|Name|etc.) macros all rely on the
`___tracy_scoped_zone` name.
This commit is contained in:
Lukas Bergdoll
2025-09-29 18:49:56 +02:00
parent 0a5aa506b6
commit abd7c4f317

View File

@@ -149,10 +149,32 @@
#define ZoneTransientN( varname, name, active ) tracy::ScopedZone varname( TracyLine, TracyFile, strlen( TracyFile ), TracyFunction, strlen( TracyFunction ), name, strlen( name ), TRACY_CALLSTACK, active )
#define ZoneTransientNC( varname, name, color, active ) tracy::ScopedZone varname( TracyLine, TracyFile, strlen( TracyFile ), TracyFunction, strlen( TracyFunction ), name, strlen( name ), color, TRACY_CALLSTACK, active )
#define ZoneScoped ZoneNamed( ___tracy_scoped_zone, true )
#define ZoneScopedN( name ) ZoneNamedN( ___tracy_scoped_zone, name, true )
#define ZoneScopedC( color ) ZoneNamedC( ___tracy_scoped_zone, color, true )
#define ZoneScopedNC( name, color ) ZoneNamedNC( ___tracy_scoped_zone, name, color, true )
#if defined(__clang__)
#define SuppressVarShadowWarning(Expr) \
_Pragma("clang diagnostic push"); \
_Pragma("clang diagnostic ignored \"-Wshadow\""); \
Expr; \
_Pragma("clang diagnostic pop");
#elif defined(__GNU__)
#define SuppressVarShadowWarning(Expr) \
_Pragma("GCC diagnostic push"); \
_Pragma("GCC diagnostic ignored \"-Wshadow\""); \
Expr; \
_Pragma("GCC diagnostic pop");
#elif defined(_MSC_VER)
#define SuppressVarShadowWarning(Expr) \
_Pragma("warning(push)"); \
_Pragma("warning(disable : 4456)"); \
Expr; \
_Pragma("warning(pop)");
#else
#define SuppressVarShadowWarning(Expr) Expr
#endif
#define ZoneScoped SuppressVarShadowWarning( ZoneNamed( ___tracy_scoped_zone, true ) )
#define ZoneScopedN( name ) SuppressVarShadowWarning( ZoneNamedN( ___tracy_scoped_zone, name, true ) )
#define ZoneScopedC( color ) SuppressVarShadowWarning( ZoneNamedC( ___tracy_scoped_zone, color, true ) )
#define ZoneScopedNC( name, color ) SuppressVarShadowWarning( ZoneNamedNC( ___tracy_scoped_zone, name, color, true ) )
#define ZoneText( txt, size ) ___tracy_scoped_zone.Text( txt, size )
#define ZoneTextV( varname, txt, size ) varname.Text( txt, size )