[clang] [APINotes] Add Where.Object selectors for C++ methods (PR #216148)

via cfe-commits cfe-commits at lists.llvm.org
Wed Aug 19 04:02:38 PDT 2026


================
@@ -1397,28 +1440,73 @@ void Sema::ProcessAPINotes(Decl *D) {
             auto Info = Reader->lookupCXXMethod(Context->id, MethodName);
             ProcessVersionedAPINotes(*this, CXXMethod, Info);
 
-            if (ParameterSelectorCandidates)
+            auto &DiagnosticState =
+                getAPINotesSelectorDiagnosticState(*this, Reader);
+            if (auto NameOnlyKey =
+                    Reader->getCXXMethodSelectorKey(Context->id, MethodName))
+              DiagnosticState.noteSeenDeclaration(*NameOnlyKey, MethodName,
+                                                  CXXMethod->getLocation());
+
+            if (ParameterSelectorCandidates) {
               processExactAPINotes<api_notes::CXXMethodInfo>(
                   *this, CXXMethod, *ParameterSelectorCandidates,
                   [&](ArrayRef<std::string> Parameters) {
                     return Reader->lookupCXXMethod(Context->id, MethodName,
                                                    Parameters);
                   });
-
-            if (ParameterSelectorCandidates) {
-              auto &DiagnosticState =
-                  getAPINotesSelectorDiagnosticState(*this, Reader);
-              if (auto BroadKey =
-                      Reader->getCXXMethodSelectorKey(Context->id, MethodName))
-                DiagnosticState.noteSeenDeclaration(*BroadKey, MethodName,
-                                                    CXXMethod->getLocation());
               DiagnosticState.markCandidatesUsed(
                   [&](ArrayRef<std::string> Parameters) {
                     return Reader->getCXXMethodSelectorKey(
                         Context->id, MethodName, Parameters);
                   },
                   *ParameterSelectorCandidates);
             }
+
+            if (CXXMethod->isImplicitObjectMemberFunction()) {
+              SmallVector<api_notes::FunctionObjectSelector, 7> ObjectSelectors;
+              getAPINotesObjectSelectorSubsets(
+                  getAPINotesObjectSelector(CXXMethod), ObjectSelectors);
+              // Apply every matching object selector in increasing specificity.
----------------
StoeckOverflow wrote:

The increasing-specificity order gives us the intended precedence when multiple matching notes set the same field. A less constrained `Object` selector acts like a default for a family of methods, and a more constrained selector refines that default.

For example, `Object: { Const: true }` can apply to all const methods, while `Object: { Const: true, Ref: lvalue }` applies only to const lvalue-ref-qualified methods. If both match and both set the same API-notes field, applying the broad selector first means the later, more specific note can override that field.

https://github.com/llvm/llvm-project/pull/216148


More information about the cfe-commits mailing list