mirror of
https://github.com/wolfpld/tracy.git
synced 2026-10-06 00:45:21 +00:00
Merge pull request #1160 from Voultapher/suppress-variable-shadowing-warnings
Suppress variable shadowing warnings
This commit is contained in:
@@ -1397,7 +1397,7 @@ void Function()
|
||||
}
|
||||
\end{lstlisting}
|
||||
|
||||
This doesn't stop some compilers from dispensing \emph{fashion advice} about variable shadowing (as both \texttt{ZoneScoped} calls create a variable with the same name, with the inner scope one shadowing the one in the outer scope). If you want to avoid these warnings, you will also need to use the \texttt{ZoneNamed} macros.
|
||||
This doesn't stop some compilers from dispensing \emph{fashion advice} about variable shadowing (as both \texttt{ZoneScoped} calls create a variable with the same name, with the inner scope one shadowing the one in the outer scope). By default the produced warnings are suppressed when using clang, gcc or MSVC. This behavior can be opted out of by defining \texttt{TRACY\_ALLOW\_SHADOW\_WARNING}. An alternative approach avoids variable name shadowing by manually defining zone names with \texttt{ZoneNamed}. Using this approach requires using the V variants of zone macros like \texttt{ZoneTextV}.
|
||||
|
||||
\subsubsection{Exiting program from within a zone}
|
||||
|
||||
|
||||
@@ -149,10 +149,34 @@
|
||||
#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(TRACY_ALLOW_SHADOW_WARNING)
|
||||
#define SuppressVarShadowWarning(Expr) Expr
|
||||
#elif 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 )
|
||||
|
||||
Reference in New Issue
Block a user