[PATCH] D23385: Implement __has_constant_initializer(obj) expression traits.

Richard Smith via cfe-commits cfe-commits at lists.llvm.org
Thu Aug 11 19:33:05 PDT 2016


rsmith added a comment.

Have you considered modelling this as an attribute on the declaration of the variable instead of as a separate check? If so, why do you prefer this approach? (If I were to suggest this for standardization, an attribute is the approach I'd probably take.)


================
Comment at: lib/AST/Expr.cpp:2653-2662
@@ -2651,4 +2652,12 @@
     }
-
+    if (CE->getConstructor()->isConstexpr() &&
+        (CE->getConstructor()->getParent()->hasTrivialDestructor() ||
+            AllowNonLiteral)) {
+        for (auto *Arg : CE->arguments()) {
+          if (!Arg->isConstantInitializer(Ctx, false, Culprit))
+            return false;
+        }
+        return true;
+    }
     break;
   }
----------------
This doesn't look right: just because we're calling a constexpr constructor with constant arguments doesn't imply that the initializer is constant.


https://reviews.llvm.org/D23385





More information about the cfe-commits mailing list