Skip to content

Commit

Permalink
Fix clang-13 unused-private-field
Browse files Browse the repository at this point in the history
This change guards unused private members that exist purely
for ABI compatibility between USD builds with and without
Python support enabled (see #1716) with a new pragma to
disable warnings on clang.

Part of PR #1684 from @charlesfleche

(Internal change: 2265598)
  • Loading branch information
sunyab authored and pixar-oss committed Mar 14, 2023
1 parent f08f530 commit 73622a0
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
7 changes: 7 additions & 0 deletions pxr/base/arch/pragmas.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,9 @@
#define ARCH_PRAGMA_UNUSED_FUNCTION \
_Pragma("clang diagnostic ignored \"-Wunused-function\"")

#define ARCH_PRAGMA_UNUSED_PRIVATE_FIELD \
_Pragma("clang diagnostic ignored \"-Wunused-private-field\"")

#define ARCH_PRAGMA_INSTANTIATION_AFTER_SPECIALIZATION \
_Pragma("clang diagnostic ignored \"-Winstantiation-after-specialization\"")

Expand Down Expand Up @@ -195,6 +198,10 @@
#define ARCH_PRAGMA_UNUSED_FUNCTION
#endif

#if !defined ARCH_PRAGMA_UNUSED_PRIVATE_FIELD
#define ARCH_PRAGMA_UNUSED_PRIVATE_FIELD
#endif

#if !defined ARCH_PRAGMA_MACRO_TOO_FEW_ARGUMENTS
#define ARCH_PRAGMA_MACRO_TOO_FEW_ARGUMENTS
#endif
Expand Down
4 changes: 4 additions & 0 deletions pxr/base/tf/pyObjWrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include "pxr/pxr.h"

#include "pxr/base/tf/api.h"
#include "pxr/base/arch/pragmas.h"

#ifdef PXR_PYTHON_SUPPORT_ENABLED
// Include this header first to pick up additional mitigations
Expand Down Expand Up @@ -57,7 +58,10 @@ class TfPyObjWrapperStub
static constexpr std::size_t Align = 8;

private:
ARCH_PRAGMA_PUSH
ARCH_PRAGMA_UNUSED_PRIVATE_FIELD
std::aligned_storage<Size, Align>::type _stub;
ARCH_PRAGMA_POP
};


Expand Down
12 changes: 12 additions & 0 deletions pxr/base/trace/collector.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@
#include "pxr/base/tf/weakBase.h"
#include "pxr/base/tf/weakPtr.h"

#include "pxr/base/arch/pragmas.h"

#include <atomic>
#include <string>
#include <vector>
Expand Down Expand Up @@ -619,8 +621,18 @@ class TraceCollector : public TfWeakBase {

TimeStamp _measuredScopeOverhead;

// These members are unused if Python support is disabled. However, we
// leave them in place and just mark them unused to provide ABI
// compatibility between USD builds with and without Python enabled.
#ifndef PXR_PYTHON_SUPPORT_ENABLED
ARCH_PRAGMA_PUSH
ARCH_PRAGMA_UNUSED_PRIVATE_FIELD
#endif
std::atomic<int> _isPythonTracingEnabled;
TfPyTraceFnId _pyTraceFnId;
#ifndef PXR_PYTHON_SUPPORT_ENABLED
ARCH_PRAGMA_POP
#endif
};

TRACE_API_TEMPLATE_CLASS(TfSingleton<TraceCollector>);
Expand Down

0 comments on commit 73622a0

Please sign in to comment.