[clang] [clang] Add the candiscard attribute to suppress nodiscard (PR #154943)

Erich Keane via cfe-commits cfe-commits at lists.llvm.org
Fri Aug 22 08:11:55 PDT 2025


================
@@ -3646,6 +3646,14 @@ def Unavailable : InheritableAttr {
   let MeaningfulToClassTemplateDefinition = 1;
 }
 
+def CanDiscard : InheritableAttr {
+  let Spellings = [CXX11<"clang", "candiscard">,
+                   GCC<"candiscard">];
+  let Subjects = SubjectList<[ObjCMethod, FunctionLike, TypedefName]>;
----------------
erichkeane wrote:

Are we sure about this subject list?  `ObjCMethod` seems odd here, and `FunctionLike` ALSO allows this to be added to function/mem function pointers/references/etc.  I suspect this whole list should just be `Function` + `TypedefName` (though maybe `Typedef` and `TypeAlias`, as including Objective C ParamDecls seems odd here).

IF you leave any of the above, please make sure that ALL of the FunctionLike has well defined semantics/etc, and that the ObjectiveC types are tested/have well defined semantics.

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


More information about the cfe-commits mailing list