You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@thrift.apache.org by "Benjamin Gemmill (Jira)" <ji...@apache.org> on 2022/09/22 19:16:00 UTC

[jira] [Created] (THRIFT-5637) Thrift compiler should be able to output c++ Aggregate types

Benjamin Gemmill created THRIFT-5637:
----------------------------------------

             Summary: Thrift compiler should be able to output c++ Aggregate types
                 Key: THRIFT-5637
                 URL: https://issues.apache.org/jira/browse/THRIFT-5637
             Project: Thrift
          Issue Type: Improvement
          Components: C++ - Compiler
    Affects Versions: 0.17.0, 0.16.0
            Reporter: Benjamin Gemmill


If we have a thrift struct defined like this:

{{struct thingamabob {}}
{{    1: i64 a = 0}}
{{    2: i64 b = 0}}
{{    3: i64 c = 0}}
{{}}}

Then the generated code contains a few constructors and assignment operators that look like this:
{{thingamabob(const thingamabob&) noexcept;}}
{{thingamabob&operator=(const thingamabob&) noexcept;}}
{{{}thingamabob() noexcept{}}}{{{}: a(0),{}}}{{{}b(0),{}}}{{{}c(0) {{}}}{{{}}{}}}
The issue here is that while this class could be an [AggregateType|http://example.com] and support aggregate initialization, the way these defaults are generated prevent it.

If instead, thrift used default initializers like this where the the member objects are defined:
int64_t a\{0};
int64_t b\{0};
int64_t c\{0};
We could then initialize thrift structs with initializer lists, expect 
static_assert(std::is_aggregate_v<type>) to work, and we'd still have default construction and copying.
 
For this to work, the "templates" option passed to the c++ compiler should remove the virtual keyword from the generated printTo functions, and the generated __isset structs would also need to be changed similarly to look like:
{{typedef struct_thingamabob__isset {}}
{{bool a :1\{false};}}
{{bool b :1\{false};}}
{{bool c :1\{false};}}
{{} _thingamabob__isset;}}
 
{{Happy to take a stab at this and wanted to check for feedback first.}}



--
This message was sent by Atlassian Jira
(v8.20.10#820010)