-
Notifications
You must be signed in to change notification settings - Fork 13.6k
[clang] Add scoped enum support to StreamingDiagnostic
#138089
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -1429,6 +1429,22 @@ operator<<(const StreamingDiagnostic &DB, T *DC) { | |||||||||||||
return DB; | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
// Convert scope enums to their underlying type, so that we don't have | ||||||||||||||
// clutter the emitting code with `llvm::to_underlying()`. | ||||||||||||||
// We also need to disable implicit conversion for the first argument, | ||||||||||||||
// because classes that derive from StreamingDiagnostic define their own | ||||||||||||||
// templated operator<< that accept a wide variety of types, leading | ||||||||||||||
// to ambiguity. | ||||||||||||||
template <typename T, typename U> | ||||||||||||||
inline std::enable_if_t< | ||||||||||||||
std::is_same_v<std::remove_const_t<T>, StreamingDiagnostic> && | ||||||||||||||
llvm::is_scoped_enum_v<std::remove_reference_t<U>>, | ||||||||||||||
const StreamingDiagnostic &> | ||||||||||||||
operator<<(const T &DB, U &&SE) { | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure why There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If I do what you suggest, this pre-existing llvm-project/clang/include/clang/Basic/Diagnostic.h Lines 1297 to 1302 in 1121a49
causes the following ambiguity:
This patch is far from my first attempt to implement this, but the first one that didn't run into one of those ambiguity errors. Overload set of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Given only two classes seem to inherit from StreamingDiagnostic, maybe we can add an overload to each of them? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I tried that. First you add an overload, then you need to modify the existing overload to not be a viable candidate when a scoped enum is passed. The new overload also have to copy any checks or asserts that the old one does, otherwise they will be skipped. I wasn't able to make it work, and it would be more complicated than the approach here anyway. |
||||||||||||||
DB << llvm::to_underlying(SE); | ||||||||||||||
return DB; | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
inline const StreamingDiagnostic &operator<<(const StreamingDiagnostic &DB, | ||||||||||||||
SourceLocation L) { | ||||||||||||||
DB.AddSourceRange(CharSourceRange::getTokenRange(L)); | ||||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need for this to be
std::remove_cvref_t
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I checked that
const
qualifier doesn't get in the way, and that's what we do in other similar cases. Happy to be proven wrong by buildbots.