[ 
https://issues.apache.org/jira/browse/THRIFT-5637?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Jens Geyer resolved THRIFT-5637.
--------------------------------
    Fix Version/s: 0.22.0
         Assignee: Alkis Evlogimenos
       Resolution: Fixed

Thanks!

> 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.16.0, 0.17.0
>            Reporter: Benjamin Gemmill
>            Assignee: Alkis Evlogimenos
>            Priority: Major
>             Fix For: 0.22.0
>
>          Time Spent: 40m
>  Remaining Estimate: 0h
>
> 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)

Reply via email to