[cfe-dev] Constant expression checking rewrite

Ted Kremenek kremenek at apple.com
Sat May 17 21:44:36 PDT 2008

On May 17, 2008, at 9:30 PM, Ted Kremenek wrote:

> On May 16, 2008, at 7:26 PM, Eli Friedman wrote:
>> I'm not exactly sure why the DeadStores pass cares if the value is
>> constant; maybe it should just be checking for zero and other common
>> "dummy" initializations?
> I found that defining the scope of dummy initializations is not really
> tractable.  Simply checking for a constant assignment was 99% accurate
> in pruning out dead stores resulting from defensive programming.
> Aside from the dead store checker, I can see other cases in the static
> analyzer (and other clients such as refactoring) where knowing whether
> or not an expression is a constant expression is very useful.

I apologize for digressing this thread, so I want to return to the  
original point.  I think having Sema more accurately reflect what is a  
C99 constant expression is good thing (as done by your patch).

My question now is what is the harm about Expr::isConstantExpr?  This  
hasn't been made clear in this thread.  Is the name just misleading?   
Does it return true when something isn't a constant expression?  I  
don't have a problem removing it, but I'm trying to understand what  
the problem is, especially since there are clients of it outside of  
Sema.  For the clients outside of Sema (including potential future  
clients who want to do similar queries on expressions), I want to  
understand what is fundamentally wrong or limited about  
Expr::isConstantExpr as it is now.

I understand that there is an issue of cleanly implementing the  
checking of constant expressions in Sema so that we can report  
diagnostics (as done in your patch), and that keeping isConstantExpr  
in Expr makes this a little more difficult to do cleanly.  Is this the  
main issue?

More information about the cfe-dev mailing list