[clang] [Clang] Add template argument support for {con,de}structor attributes. (PR #151400)
Erich Keane via cfe-commits
cfe-commits at lists.llvm.org
Fri Aug 15 06:32:33 PDT 2025
================
@@ -2152,29 +2152,49 @@ static void handleUnusedAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
D->addAttr(::new (S.Context) UnusedAttr(S.Context, AL));
}
+static std::optional<Expr *>
+sharedGetConstructorDestructorAttrExpr(Sema &S, const ParsedAttr &AL) {
+ // If no Expr node exists on the attribute, return a nullptr (default priority to be used).
+ // If Expr node exists but is not valid, return a nullopt.
+ // Otherwise, return the Expr.
+ Expr *E = nullptr;
+ if (AL.getNumArgs() == 1) {
+ E = AL.getArgAsExpr(0);
+ if (E->isValueDependent()) {
+ if (!E->isTypeDependent() && !E->getType()->isIntegerType()) {
+ S.Diag(AL.getLoc(), diag::err_attribute_argument_type)
+ << AL << AANT_ArgumentIntegerConstant << E->getSourceRange();
+ return std::nullopt;
+ }
+ } else {
+ uint32_t priority;
+ if (!S.checkUInt32Argument(AL, AL.getArgAsExpr(0), priority)) {
----------------
erichkeane wrote:
Yep! exactly! You have an additional couple of APInt/APValue/etc casts there (just do `llvm::APSInt::getUnsigned(priority)`),
https://github.com/llvm/llvm-project/pull/151400
More information about the cfe-commits
mailing list