use -fno-access-control instead of -Dprivate=public for tests#3346
Conversation
chenBright
left a comment
There was a problem hiding this comment.
I think using -fno-access-control, like in test/BUILD.bazel, would be more reasonable.
Line 26 in 1725896
| # if __cplusplus >= 201703L | ||
| # include <any> | ||
| # endif | ||
| # define private public |
There was a problem hiding this comment.
Using -fno-access-control instead of # define private public?
|
Good point! I'll update the PR to:
The Bazel build already uses |
|
test/Makefile also needs to be updated. Line 21 in 1725896 |
3354e3d to
5b9b747
Compare
| #else | ||
| # include <sstream> | ||
| #endif | ||
| // Previously, tests used -Dprivate=public to access private members. |
There was a problem hiding this comment.
The file test/sstream_workaround.h can be deleted, right?
There was a problem hiding this comment.
Pull request overview
This PR updates the test build configuration to avoid C++ standard library compilation failures caused by the historical -Dprivate=public/-Dprotected=public approach (notably when <any> is pulled in under C++17).
Changes:
- Remove
-Dprivate=public/-Dprotected=publicfrom test builds and switch to-fno-access-controlto bypass access checks without rewriting tokens in headers. - Drop forced inclusion of
test/sstream_workaround.hfrom test build flags and simplify the header to comments-only.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| test/sstream_workaround.h | Removes the old forced-include workaround logic and leaves explanatory comments. |
| test/Makefile | Replaces -Dprivate=public/-Dprotected=public with -fno-access-control for the Makefile-based test build. |
| test/CMakeLists.txt | Replaces -Dprivate=public/-Dprotected=public with -fno-access-control for the CMake-based test build. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
5b9b747 to
e2aaeb4
Compare
Yes, I'm removing all sstream_workaround references from test/BUILD.bazel now. The fix will be pushed shortly. |
Replace the -Dprivate=public/-Dprotected=public macro hack with -fno-access-control compiler flag in test builds. This avoids redeclaration issues with standard library headers (e.g. <any> under C++17) while still allowing tests to access private members. Changes: - test/CMakeLists.txt: replace -Dprivate=public with -fno-access-control - test/Makefile: replace -Dprivate=public with -fno-access-control - test/BUILD.bazel: remove sstream_workaround cc_library and all deps - test/sstream_workaround.h: remove workaround (no longer needed)
8e6d2a9 to
febb5a1
Compare
Summary
Replace
-Dprivate=public -Dprotected=publicmacro hack with-fno-access-controlcompiler flag in CMake and Makefile test builds. The macro approach caused redeclaration errors with standard library headers (<sstream>,<any>, etc.) that use private access specifiers internally.-fno-access-controlis a GCC/Clang compiler flag that cleanly disables access control checking without affecting header parsing. The Bazel build already uses this flag attest/BUILD.bazel:26, so this makes CMake and Makefile builds consistent with Bazel.Fixes #3345
Changes
test/CMakeLists.txt: Replace-Dprivate=public -Dprotected=public -include sstream_workaround.hwith-fno-access-controltest/Makefile: Same changetest/sstream_workaround.h: Deleted (no longer referenced)Test plan