[cfe-dev] const_cast and p0388 (array boundloss becomes const_cast)

Nathan Sidwell via cfe-dev cfe-dev at lists.llvm.org
Wed Apr 14 08:49:23 PDT 2021


P0388 
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2019/p0388r4.html 
Makes conversions between bounded-array and unbounded-array look like 
qualification conversions.  This means you can use const-cast to add 
array bounds (and implicitly lose bounds)

But, ConstCast has a cast-kind of CK_NoOp:
AST/ExprCXX.h:
   CXXConstCastExpr(QualType ty, ExprValueKind VK, Expr *op,
                    TypeSourceInfo *writtenTy, SourceLocation l,
                    SourceLocation RParenLoc, SourceRange AngleBrackets)
       : CXXNamedCastExpr(CXXConstCastExprClass, ty, VK, CK_NoOp, op, 0,
                          /*HasFPFeatures*/ false, writtenTy, l, RParenLoc,
                          AngleBrackets) {}

That will no longer be true -- adding or removing bounds changes the 
type more than CK_NoOp permits.  This results in code emission assert 
failure when things like [4 x i32]* meets [0 x i32]*.

so, should such constcasts generate non-ConstCast AST?, or should the 
ConstCast node sometimes not be CK_NoOp?  The latter seems better to me, 
but perhaps there's a different opinion?

nathan

-- 
Nathan Sidwell


More information about the cfe-dev mailing list