You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@thrift.apache.org by "zsy056 (via GitHub)" <gi...@apache.org> on 2025/12/31 05:24:42 UTC
[PR] cpp: add `private_optional` support (and wire up tests/CI) [thrift]
zsy056 opened a new pull request, #3278:
URL: https://github.com/apache/thrift/pull/3278
Add a new `cpp:private_optional` generator option for C++ that emits optional fields as private members and provides const getters, enabling stricter encapsulation while preserving access for generated helpers.
To keep the feature stable and exercised in automation, add fixture-based compiler tests and the minimal build/CI wiring required for those tests to build and run in the workflow (including MSVC).
### Example generated code (behavior change only, from `TestStruct`)
#### Default (no `cpp:private_optional`): optional fields stay public
```cpp
public:
int32_t required_field;
int32_t optional_field;
std::string optional_string;
```
With cpp:private_optional: optional fields become private + const getters
```cpp
public:
int32_t required_field;
const int32_t& __get_optional_field() const { return optional_field; }
const std::string& __get_optional_string() const { return optional_string; }
private:
int32_t optional_field;
std::string optional_string;
friend void swap(TestStruct &a, TestStruct &b) noexcept;
friend std::ostream& operator<<(std::ostream& out, const TestStruct& obj);
```
<!-- Explain the changes in the pull request below: -->
<!-- We recommend you review the checklist/tips before submitting a pull request. -->
- [ ] Did you create an [Apache Jira](https://issues.apache.org/jira/projects/THRIFT/issues/) ticket? ([Request account here](https://selfserve.apache.org/jira-account.html), not required for trivial changes)
- [ ] If a ticket exists: Does your pull request title follow the pattern "THRIFT-NNNN: describe my issue"?
- [x] Did you squash your changes to a single commit? (not required, but preferred)
- [x] Did you do your best to avoid breaking changes? If one was needed, did you label the Jira ticket with "Breaking-Change"?
- [ ] If your change does not involve any code, include `[skip ci]` anywhere in the commit message to free up build resources.
<!--
The Contributing Guide at:
https://github.com/apache/thrift/blob/master/CONTRIBUTING.md
has more details and tips for committing properly.
-->
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@thrift.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] add `private_optional` support (and wire up tests/CI) [thrift]
Posted by "zsy056 (via GitHub)" <gi...@apache.org>.
zsy056 commented on PR #3278:
URL: https://github.com/apache/thrift/pull/3278#issuecomment-3745734045
> I would love to also see a second opinion from the c++ Thrift committers.
Hi Jens, wondering if you have a specific set of folks in mind that needed to be mentioned in the PR?
Thanks
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@thrift.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] add `private_optional` support (and wire up tests/CI) [thrift]
Posted by "Jens-G (via GitHub)" <gi...@apache.org>.
Jens-G merged PR #3278:
URL: https://github.com/apache/thrift/pull/3278
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@thrift.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] add `private_optional` support (and wire up tests/CI) [thrift]
Posted by "zsy056 (via GitHub)" <gi...@apache.org>.
zsy056 commented on code in PR #3278:
URL: https://github.com/apache/thrift/pull/3278#discussion_r2687546336
##########
compiler/cpp/tests/cpp/expected_TestStruct_default.txt:
##########
@@ -0,0 +1,35 @@
+class TestStruct : public virtual ::apache::thrift::TBase {
Review Comment:
Sure, added ASF file header to these test data files as well.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@thrift.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] add `private_optional` support (and wire up tests/CI) [thrift]
Posted by "Jens-G (via GitHub)" <gi...@apache.org>.
Jens-G commented on code in PR #3278:
URL: https://github.com/apache/thrift/pull/3278#discussion_r2680539559
##########
compiler/cpp/tests/cpp/expected_TestStruct_default.txt:
##########
@@ -0,0 +1,35 @@
+class TestStruct : public virtual ::apache::thrift::TBase {
Review Comment:
Not sure how we do that but is there a way to add the ASF file header anyway at these?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@thrift.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] add `private_optional` support (and wire up tests/CI) [thrift]
Posted by "Jens-G (via GitHub)" <gi...@apache.org>.
Jens-G commented on code in PR #3278:
URL: https://github.com/apache/thrift/pull/3278#discussion_r2670152440
##########
compiler/cpp/tests/thrift_test_parser_support.cc:
##########
@@ -0,0 +1,132 @@
+// Minimal parser support for compiler unit tests.
Review Comment:
there is a number of new files lacking the ASSF license header
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@thrift.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] add `private_optional` support (and wire up tests/CI) [thrift]
Posted by "Jens-G (via GitHub)" <gi...@apache.org>.
Jens-G commented on code in PR #3278:
URL: https://github.com/apache/thrift/pull/3278#discussion_r2670152440
##########
compiler/cpp/tests/thrift_test_parser_support.cc:
##########
@@ -0,0 +1,132 @@
+// Minimal parser support for compiler unit tests.
Review Comment:
there is a number of new files lacking the ASF license header
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@thrift.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] add `private_optional` support (and wire up tests/CI) [thrift]
Posted by "zsy056 (via GitHub)" <gi...@apache.org>.
zsy056 commented on code in PR #3278:
URL: https://github.com/apache/thrift/pull/3278#discussion_r2670209587
##########
compiler/cpp/tests/thrift_test_parser_support.cc:
##########
@@ -0,0 +1,132 @@
+// Minimal parser support for compiler unit tests.
Review Comment:
thanks, added the ASF license header.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@thrift.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org