<%!

  Copyright (c) Facebook, Inc. and its affiliates.

  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at

      http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.

%>  enum Type {
    __EMPTY__ = 0,
<%#struct:fields%>
    <%field:cpp_name%> = <%field:key%>,
<%/struct:fields%>
  } ;

<%!

  Copyright (c) Facebook, Inc. and its affiliates.

  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at

      http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.

%>  enum Type : int {
    __EMPTY__ = 0,
<%#struct:fields%>
    <%field:cpp_name%> = <%field:key%>,
<%/struct:fields%>
  } ;

Make `union` generated a fixed enum
Make `union` generated a fixed enum

Summary:
An unscoped unfixed enum leads to UB if you try to cast to it from eg int. This means it's very hard to provide eg lazy deserialization: https://fb.workplace.com/groups/thriftusers/permalink/486200852089332/

This diff changes the Thrift generator to just fix the enum to int. This makes casts no longer UB. It should also be a safe change as it doesn't change any previously valid behavior.

The codegen for Thrift `enum` already has this behavior: https://fburl.com/diffusion/7lohh6ev

Reviewed By: ximyu

Differential Revision: D19496674

fbshipit-source-id: 32c27f5b8a609aa8878a8700793d8edff66a0964
