Add operator<< to the enum macro family - #5115
Open
CharlieL7 wants to merge 1 commit into
Open
Conversation
Generate std::ostream& operator<<(std::ostream&, name) alongside to_string for every MIGRAPHX_ENUM variant, so a named enum streams as its enumerator name instead of its underlying integer. The overload is an exact match, so it wins over the conversion to the underlying type for unscoped enums, and it is emitted after to_string so the nested (friend) variant reaches it by ADL. The namespace-scope variants now take their linkage from MIGRAPHX_DETAIL_ENUM_INLINE ([[maybe_unused]] inline). These enums belong in an anonymous namespace in a .cpp, which gives the generated helpers internal linkage, so any the file never calls would otherwise trip -Wunused-function. Co-authored-by: Cursor <cursoragent@cursor.com>
operator<< to the enum macro family
Contributor
There was a problem hiding this comment.
Pull request overview
This PR extends the MIGRAPHX_ENUM* macro family to also generate std::ostream& operator<<(std::ostream&, Enum) alongside the existing to_string/from_string support, so reflected enums stream as their enumerator names rather than underlying integers (including nested enums commonly used in ops).
Changes:
- Generate
operator<<for allMIGRAPHX_ENUMvariants (unscoped, scoped, nested, nested scoped). - Add
[[maybe_unused]]to namespace-scope helper linkage to avoid unused-function warnings in internal-linkage contexts. - Add unit tests validating streaming behavior (including nested enums, enums in
migraphxnamespace, and error-on-unknown).
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
src/include/migraphx/enum.hpp |
Adds macro-generated operator<< (and related helper linkage tweak) to stream enums by name. |
test/enum.cpp |
Adds test coverage for enum streaming and a stream_range integration scenario. |
Comment on lines
+179
to
+182
| // Linkage for the namespace-scope variants. These enums belong in an anonymous namespace in a .cpp, | ||
| // which gives the helpers internal linkage, so any the file never calls would trip | ||
| // -Wunused-function. The nested variants generate hidden friends and need no marking. | ||
| #define MIGRAPHX_DETAIL_ENUM_INLINE [[maybe_unused]] inline |
Regressions detected 🔴 * No develop baseline was found for this PR's branch point; compared against the latest available develop run instead. |
|
pfultz2
approved these changes
Aug 5, 2026
TedThemistokleous
approved these changes
Aug 6, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
operator<<(stream, enum)to the enum macros such that it is automatically included.Technical Details
Generate std::ostream& operator<<(std::ostream&, name) alongside to_string for every MIGRAPHX_ENUM variant.
So a named enum streams as its enumerator name instead of its underlying integer.
Changelog Category
Add a
CHANGELOG.mdentry for any option other thanNot ApplicableFollow the LLVM AI Tool Use Policy for contributions using AI.