<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/55056>55056</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            [clang-tidy] Enhance modernize-macro-to-enum to recognize constant literal expressions involving other macros
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            enhancement,
            clang-tidy
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
            LegalizeAdulthood
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          LegalizeAdulthood
      </td>
    </tr>
</table>

<pre>
    Consider the following code where macros are used to identify bitwise fields in an integral value:
```
#define FLAG_USER 0x1
#define FLAG_GROUP 0x2
#define FLAG_OTHER 0x4
#define FLAG_ALL (FLAG_USER | FLAG_GROUP | FLAG_OTHER)
```

Modernize-macro-to-enum will convert the first three macros to enums, but leave the fourth macro intact because it expands to an expression involving other macros.

Enhance the check to recognize macros that expand to expressions involving integral literals and names that also resolve to integral literals, whether they are macro names, the names of existing `const` integral values or the names of existing enums.  (A previous version of modernize-macro-to-enum may have converted earlier macros into enums already.)

The above code should transform to:
```
enum {
  FLAG_USER = 0x1,
  FLAG_GROUP = 0x2,
  FLAG_OTHER = 0x4,
  FLAG_ALL = (FLAG_USER | FLAG_GROUP | FLAG_OTHER)
};
```

Care must be taken to ensure that any names referenced in the initializing expression have already been declared, or a [compile error will result](https://godbolt.org/z/qoGvrEfPG).
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJydVE1zmzAQ_TX4orGHCGObAwfHTtJDOsmkybkj0AJqhJRKwo7z67sS-CNu3ENnbIllpf14-x6F5rt8pZUVHAxxDZBKS6m3QtWk1BzItgEDpGWl0ZYwfOwscOI0wQvKiWpHCuG2wuJFAZJbIhRhClcHtWGSbJjsIEqWUbyO4mU0i4dfb9KEQyUUkNv75d3Plx83TyR-v_rSeff08PKIXvql9-H5W7g7_dK7vL8nEV0ck0Tz1WnUgxnCRDT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