tinloaf opened a new pull request, #2755:
URL: https://github.com/apache/thrift/pull/2755

   Overview
   =======
   
   Both the default constructor and operator== implementations reference 
certain member functions of the class' members. As an example, the default 
constructor references (i.e., "uses") the default constructors of its members.
   
   If a class contains a std::vector<Foo>, and Foo has only been *forward*- 
declared (which happens often in Thrift-generated code), this creates undefined 
behavior: The std::vector specification states that as long as Foo is an 
incomplete type, it is fine to reference std::vector<Foo>, but not any members 
(such as its default constructor).
   
   Thus, we must defer our default constructor's implementation (which 
references the default constructor of std::vector<Foo>) to a point where Foo is 
a complete type. That is the case in the .cpp file.
   
   The same holds for operator==.
   
   Example
   ======
   
   Take this very simple Thrift file:
   ```
   struct StructA {
       11:required list<StructB> myBs
   }
   
   struct StructB
   {
       1:required string someString
   }
   ```
   
   If I compile this using `thrift --gen cpp:no_skeleton -o out ./file.thrift` 
I get a file that contains the following (full file 
[here](https://gist.github.com/tinloaf/1f7ae57df383d7b87221598e4f7a700d) ):
   
   ```
    class StructA;
    class StructB;
   
    class StructA : … {
     public:
        …
        StructA() noexcept {
        }
        …
        std::vector<StructB>  myBs;
        …
    };
   
    …
   
    class StructB : … {
        …
    };
   ```
   
   In this case, the default constructor for `StructA` references the default 
constructor of `std::vector<StrungB>` while `StructB` is still an incomplete 
type. *This is undefined behavior.* It did apparently compile with all big 
compilers until recently, but with C++20, Clang 15 stops accepting this kind of 
construct, as you can see [here at 
CompilerExplorer](https://godbolt.org/z/xcc4av6cb).
   
   
   
   
   Checklist
   ======
   
   - [ ] Did you create an [Apache 
Jira](https://issues.apache.org/jira/projects/THRIFT/issues/) ticket?  (not 
required for trivial changes)
   **No**: I do not have a Jira account. I was told the right way to get a Jira 
account is to post to the mailing list, which [I 
did](https://lists.apache.org/thread/wmk0nb8lgrtyxrznp1ogd7b0b9whossn). I did 
not receive a response, so I just went ahead and created this PR.
   - [ ] If a ticket exists: Does your pull request title follow the pattern 
"THRIFT-NNNN: describe my issue"?
     *Note:* As far as I can tell, no ticket exists for this.
   - [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.
   
   


-- 
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-unsubscr...@thrift.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to