[clang] Diagnose problematic uses of constructor/destructor attribute (PR #67360)

Aaron Ballman via cfe-commits cfe-commits at lists.llvm.org
Tue Sep 26 09:24:40 PDT 2023


================
@@ -3176,6 +3178,11 @@ def err_alignas_underaligned : Error<
   "requested alignment is less than minimum alignment of %1 for type %0">;
 def warn_aligned_attr_underaligned : Warning<err_alignas_underaligned.Summary>,
   InGroup<IgnoredAttributes>;
+def err_ctor_dtor_attr_on_non_void_func : Error<
+  "%0 attribute can only be applied to a function which accepts no arguments "
+  "and has a 'void' or 'int' return type">;
----------------
AaronBallman wrote:

Not that I could find -- the function marked `cleanup` needs to accept one argument and it has to be a pointer type:
```
def err_attribute_cleanup_func_must_take_one_arg : Error<
  "'cleanup' function %0 must take 1 parameter">;
def err_attribute_cleanup_func_arg_incompatible_type : Error<
  "'cleanup' function %0 parameter has "
  "%diff{type $ which is incompatible with type $|incompatible type}1,2">;
```
I looked around for an existing diagnostic to augment but didn't spot any that worked well.

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


More information about the cfe-commits mailing list