================
@@ -7932,6 +7932,35 @@ ExprResult Sema::PerformQualificationConversion(Expr *E,
QualType Ty,
return ImpCastExprToType(E, Ty, CK, VK, /*BasePath=*/nullptr, CCK);
}
+static bool containsNonNullPointer(const APValue &Val) {
+ if (Val.isStruct()) {
+ unsigned int N = Val.getStructNumFields();
+ for (unsigned int I = 0; I < N; I++) {
+ if (containsNonNullPointer(Val.getStructField(I)))
+ return true;
+ }
+ } else if (Val.isUnion()) {
+ const APValue &UV = Val.getUnionValue();
+ return containsNonNullPointer(UV);
+ } else if (Val.isLValue() && !Val.isNullPointer()) {
+ return true;
+ }
+ return false;
+}
+
+// C23 6.7.1p6: If an object or subobject declared with storage-class
+// specifier constexpr has pointer, integer, or arithmetic type, any
+// explicit initializer value for it shall be null, an integer
+// constant expression, or an arithmetic constant expression,
+// respectively.
+static bool rejectConstexprValueInC(Sema &S, const APValue &Val) {
+ assert(S.getLangOpts().C23);
+ if (containsNonNullPointer(Val)) {
+ return true;
+ }
+ return false;
----------------
aalmkainzi wrote:
in case C2y makes non-null pointers allowed, this function can check
S.getLangOpts and do another branch
https://github.com/llvm/llvm-project/pull/230477
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits