[cfe-dev] Can't use sizeof ( typeof ( <vla> ))

Paulo Matos via cfe-dev cfe-dev at lists.llvm.org
Fri Nov 18 00:18:28 PST 2016



On 17/11/16 19:00, Friedman, Eli wrote:
> On 11/17/2016 7:02 AM, Paulo Matos via cfe-dev wrote:
>> The problem with this rationale is that it's not true in this case since
>> you need to evaluate typeof (a), which can't be evaluated at compile
>> time. Is it true that to fix this issue, we need to rethink how sizeof
>> are evaluated?
> 
> sizeof() and typeof() with an operand of VLA type are already
> special-cased; see Sema::TransformToPotentiallyEvaluated.
>

Actually sizeof does not seem to be special cased. Only Typeof which
calls Sema::TransformToPotentiallyEvaluated through
Sema::HandleExprEvaluationContextForTypeof. Special-casing works by
making the typeof context evaluated if the previous context is evaluated:
ExprResult Sema::TransformToPotentiallyEvaluated(Expr *E) {
  assert(isUnevaluatedContext() &&
         "Should only transform unevaluated expressions");
  ExprEvalContexts.back().Context =
      ExprEvalContexts[ExprEvalContexts.size()-2].Context;
  if (isUnevaluatedContext())
    return E;
  return TransformToPE(*this).TransformExpr(E);
}


Unfortunately the previous context is a sizeof which is not evaluated
and therefore leaves the typeof as unevaluated, hence the bug.

-- 
Paulo Matos



More information about the cfe-dev mailing list