[clang] [Clang] include attribute scope in diagnostics (PR #144619)
Aaron Ballman via cfe-commits
cfe-commits at lists.llvm.org
Thu Jun 26 04:28:32 PDT 2025
================
@@ -292,6 +297,45 @@ inline bool doesKeywordAttributeTakeArgs(tok::TokenKind Kind) {
}
}
+inline const StreamingDiagnostic &operator<<(const StreamingDiagnostic &DB,
+ const AttributeCommonInfo &CI) {
+ DB.AddTaggedVal(reinterpret_cast<uint64_t>(&CI),
+ DiagnosticsEngine::ak_attr_info);
+ return DB;
+}
+
+inline const StreamingDiagnostic &operator<<(const StreamingDiagnostic &DB,
+ const AttributeCommonInfo *CI) {
+ DB.AddTaggedVal(reinterpret_cast<uint64_t>(CI),
+ DiagnosticsEngine::ak_attr_info);
+ return DB;
+}
+
+/// AttributeCommonInfo has a non-explicit constructor which takes an
+/// SourceRange as its only argument, this constructor has many uses so making
+/// it explicit is hard. This constructor causes ambiguity with
+/// DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB, SourceRange R).
+/// We use SFINAE to disable any conversion and remove any ambiguity.
+template <
+ typename ACI,
+ std::enable_if_t<std::is_same<ACI, AttributeCommonInfo>::value, int> = 0>
+inline const StreamingDiagnostic &operator<<(const StreamingDiagnostic &DB,
+ const ACI &CI) {
+ DB.AddTaggedVal(reinterpret_cast<uint64_t>(&CI),
+ DiagnosticsEngine::ak_attr_info);
+ return DB;
+}
+
+template <
+ typename ACI,
+ std::enable_if_t<std::is_same<ACI, AttributeCommonInfo>::value, int> = 0>
+inline const StreamingDiagnostic &operator<<(const StreamingDiagnostic &DB,
----------------
AaronBallman wrote:
Do we actually need this overload? Because it accepts a pointer, it shouldn't have any ambiguity with the `AttributeCommonInfo` non-explicit constructor, right?
https://github.com/llvm/llvm-project/pull/144619
More information about the cfe-commits
mailing list