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

Erich Keane via cfe-commits cfe-commits at lists.llvm.org
Tue Sep 26 06:45:39 PDT 2023


================
@@ -171,6 +171,11 @@ Attribute Changes in Clang
   automatic diagnostic to use parameters of types that the format style
   supports but that are never the result of default argument promotion, such as
   ``float``. (`#59824: <https://github.com/llvm/llvm-project/issues/59824>`_)
+- The ``constructor`` and ``destructor`` attributes now diagnose when:
+  - the priority is not between 101 and 65535, inclusive,
+  - the function it is applied to accepts arguments or has a non-void return
----------------
erichkeane wrote:

I'm more considering a case where someone wants to use an otherwise 'normal' function as their constructor/destructor, where the return value is perhaps useful if the program is continuing (but then obviously not when it is not).  I would think that the RETURN should at minimum be only a warning (or perhaps warning-as-error?), since this is otherwise a breaking change.

The params list being nothing makes sense, because there is no valid code generation that did that before AFAIK, but an ignorable return type is meaningful.  In your `func` case, I don't see a problem with that, presume the 1st line was something like:
` if (!GlobalAllocator) InitAllocator(GlobalAllocator); `
and they were using the `constructor` call to initialize that (and not caring about the object it was returning).  This would cause this error to be breaking.

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


More information about the cfe-commits mailing list