Skip to content

Commit 5002c04

Browse files
committed
Make variable shadowing warning suppression optional
1 parent abd7c4f commit 5002c04

File tree

2 files changed

+16
-14
lines changed

2 files changed

+16
-14
lines changed

‎manual/tracy.tex‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1397,7 +1397,7 @@ \subsubsection{Variable shadowing}
13971397
}
13981398
\end{lstlisting}
13991399

1400-
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.
1400+
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}.
14011401

14021402
\subsubsection{Exiting program from within a zone}
14031403

‎public/tracy/Tracy.hpp‎

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -149,24 +149,26 @@
149149
#define ZoneTransientN( varname, name, active ) tracy::ScopedZone varname( TracyLine, TracyFile, strlen( TracyFile ), TracyFunction, strlen( TracyFunction ), name, strlen( name ), TRACY_CALLSTACK, active )
150150
#define ZoneTransientNC( varname, name, color, active ) tracy::ScopedZone varname( TracyLine, TracyFile, strlen( TracyFile ), TracyFunction, strlen( TracyFunction ), name, strlen( name ), color, TRACY_CALLSTACK, active )
151151

152-
#if defined(__clang__)
152+
#if defined(TRACY_ALLOW_SHADOW_WARNING)
153+
#define SuppressVarShadowWarning(Expr) Expr
154+
#elif defined(__clang__)
153155
#define SuppressVarShadowWarning(Expr) \
154-
_Pragma("clang diagnostic push"); \
155-
_Pragma("clang diagnostic ignored \"-Wshadow\""); \
156-
Expr; \
157-
_Pragma("clang diagnostic pop");
156+
_Pragma("clang diagnostic push") \
157+
_Pragma("clang diagnostic ignored \"-Wshadow\"") \
158+
Expr \
159+
_Pragma("clang diagnostic pop")
158160
#elif defined(__GNU__)
159161
#define SuppressVarShadowWarning(Expr) \
160-
_Pragma("GCC diagnostic push"); \
161-
_Pragma("GCC diagnostic ignored \"-Wshadow\""); \
162-
Expr; \
163-
_Pragma("GCC diagnostic pop");
162+
_Pragma("GCC diagnostic push") \
163+
_Pragma("GCC diagnostic ignored \"-Wshadow\"") \
164+
Expr \
165+
_Pragma("GCC diagnostic pop")
164166
#elif defined(_MSC_VER)
165167
#define SuppressVarShadowWarning(Expr) \
166-
_Pragma("warning(push)"); \
167-
_Pragma("warning(disable : 4456)"); \
168-
Expr; \
169-
_Pragma("warning(pop)");
168+
_Pragma("warning(push)") \
169+
_Pragma("warning(disable : 4456)") \
170+
Expr \
171+
_Pragma("warning(pop)")
170172
#else
171173
#define SuppressVarShadowWarning(Expr) Expr
172174
#endif

0 commit comments

Comments
 (0)