Uploaded image for project: 'Apache Avro'
  1. Apache Avro
  2. AVRO-3031

avrocppgen does not generate correct C++ code when the schema contains C++ reserved words.

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: 1.10.1
    • Fix Version/s: 1.11.0, 1.10.2
    • Component/s: c++
    • Labels:
      None

      Description

      If avrogencpp is run against a schema that uses C++ reserved words for field names, it will generate C++ code that cannot be compiled.

      avrogencpp currently has a list of C++ reserved words, but it only checks this list when generating an enum, fixed, or record type:
      https://github.com/apache/avro/blob/90d0a49d02416cac41962ac40d3662967febfcdb/lang/c%2B%2B/impl/avrogencpp.cc#L130-L142

      The result is, if you have a schema such as cpp-reserved-words.avsc (attached)
      and run ```avrogencpp -i cpp-reserved-wrods.avsc -o cannot-compile.cpp```, avrogencpp will generate C++ code that cannot be compiled: cannot-compile.cpp (attached).

      The fix this involves calling decorate on all names, instead of in the few places it's already called.

       

      I have a patch that fixes this and adds a unit test, and I will be opening a PR with the fix.

        Attachments

        1. cpp-reserved-wrods.avsc
          0.3 kB
          Allen Reese
        2. cannot-compile.cpp
          2 kB
          Allen Reese

          Activity

            People

            • Assignee:
              areese999 Allen Reese
              Reporter:
              areese999 Allen Reese
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: