[flang-commits] [PATCH] D137859: [flang] Restore ENUM_CLASS() to be compilation-time code

Peter Klausler via Phabricator via flang-commits flang-commits at lists.llvm.org
Sat Nov 12 11:20:24 PST 2022


klausler added a comment.

In D137859#3923215 <https://reviews.llvm.org/D137859#3923215>, @tschuett wrote:

> In D137859#3923213 <https://reviews.llvm.org/D137859#3923213>, @klausler wrote:
>
>> In D137859#3922948 <https://reviews.llvm.org/D137859#3922948>, @tschuett wrote:
>>
>>> What happens if I have 2 `ENUM_CLASS`? You did not namespace `Enum2String`. There are no tests.
>>
>> This is not a new feature, just a rework of a recent update to it.  It should work as it always has.
>>
>> Multiple instances of ENUM_CLASS in the same scope are distinguished by the name of the ENUM_CLASS.
>>
>> EnumToString will be defined in the namespace and/or class in which the reference to the ENUM_CLASS macro appears.
>
> Agreed. But you could still end up with two `EnumToString` in the same *context*. The only difference is the type of the parameter.
>
>   ENUM_CLASS(RelationalOperator, LT, LE, EQ, NE, GE, GT);
>   ENUM_CLASS(RelationalOperator2, LT, LE, EQ, NE, GE, GT);

In that case, the difference in the parameter types is sufficient to distinguish the two functions by the usual C++ function overloading rules.

  #include "enum-class.h"
  #include <iostream>
  ENUM_CLASS(RelationalOperator, LT, LE, EQ, NE, GE, GT)
  ENUM_CLASS(RelationalOperator2, LT, LE, EQ, NE, GE, GT)
  int main() {
    std::cout << EnumToString(RelationalOperator::LT) << std::endl;
    std::cout << EnumToString(RelationalOperator2::LT) << std::endl;
  }

``
LT
LT

  


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D137859/new/

https://reviews.llvm.org/D137859



More information about the flang-commits mailing list