[cfe-dev] Semantics of Value Dependent and Integral Constant Expressions

Davis, Matthew via cfe-dev cfe-dev at lists.llvm.org
Fri Nov 17 13:37:54 PST 2017


> From: Friedman, Eli; Sent: Friday, November 17, 2017 12:10 PM
> > On 11/16/2017 6:49 PM, Davis, Matthew via cfe-dev wrote:
> > In the case of sizeof(T), where T is a template type argument, T is dependent;
> >  therefore, sizeof(T) is considered a value dependent constant expression.  

> Why is sizeof(T) disallowed from being an ICE in checkInitIsICE()?

My reasoning is that VarDecl::checkInitIsICE() will trigger an assertion if a variable initializer is value dependent, for example: const size_t foo = sizeof(T);.  I realize that the frontend never expects to handle a value-dependent initializer in this case, but during error recovery a value-dependent initializer can reach the ICE check.

> For all T (excluding VLAs, which aren't part of the standard), sizeof(T)
> is an constant expression, yes.  But in general, it's impossible to tell
> whether a value-dependent expression is a constant expression, so we
> just don't check value-dependent expressions for the sake of
> simplicity.  (Consider, for example, "sizeof(T) > 10 ? 5 :
> printf("asdf");".)

That makes sense.  Thanks for the information,
-Matt


More information about the cfe-dev mailing list