areese opened a new pull request #1071:
URL: https://github.com/apache/avro/pull/1071


   https://issues.apache.org/jira/browse/AVRO-3031
   
   If avrogencpp encounters a schema with reserved words in it, it will happily 
generate a header with fields that are reserved words.
   
   The decorate function in avrogencpp was overloaded a reference to an 
std::string or const avro::Name& to allow this.
   The existing decorate function is only called on types, but it should also 
be called on names as well, which this patch fixes
   
   For example:
   
   {
     "type" : "record",
     "name" : "Words",
     "namespace" : "org.apache.avro.example",
     "fields" : [ {
       "name" : "alignas",
       "type" : "string"
     }, {
       "name" : "alignof",
       "type" : "string"
     }, {
       "name" : "and",
       "type" : "string"
     }
     ]
   }
   
   Will generate the following header file:
   
   struct Words {
       std::string alignas;
       std::string alignof;
       std::string and;
       Words() :
           alignas(std::string()),
           alignof(std::string()),
           and(std::string())
           { }
   };
   
   Which cannot be compiled by c++
   
   With this fix, the following will be generated:
   
   struct Words {
       std::string alignas_;
       std::string alignof_;
       std::string and_;
       Words() :
           alignas_(std::string()),
           alignof_(std::string()),
           and_(std::string())
           { }
   };
   
   Make sure you have checked _all_ steps below.
   
   ### Jira
   
   - [x] My PR addresses the following 
[AVRO-3031]](https://issues.apache.org/jira/browse/AVRO-3031) issues and 
references them in the PR title. For example, "AVRO-1234: My Avro PR"
     - https://issues.apache.org/jira/browse/AVRO-XXX
     - In case you are adding a dependency, check if the license complies with 
the [ASF 3rd Party License 
Policy](https://www.apache.org/legal/resolved.html#category-x).
   
   ### Tests
   
   - [x] My PR adds the following unit tests:
         * Unit tests with a schema that uses all of the reserved words that 
avrogencpp uses.
         * The unit test will fail to compile with the generated header file 
without this fix.
   
   ### Commits
   
   - [ ] My commits all reference Jira issues in their subject lines. In 
addition, my commits follow the guidelines from "[How to write a good git 
commit message](https://chris.beams.io/posts/git-commit/)":
     1. Subject is separated from body by a blank line
     1. Subject is limited to 50 characters (not including Jira issue reference)
     1. Subject does not end with a period
     1. Subject uses the imperative mood ("add", not "adding")
     1. Body wraps at 72 characters
     1. Body explains "what" and "why", not "how"
   
   ### Documentation
   
   - [ ] In case of new functionality, my PR adds documentation that describes 
how to use it.
     - All the public functions and the classes in the PR contain Javadoc that 
explain what it does
   


----------------------------------------------------------------
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.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to