This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [C++] value-dependent expressions and static_cast


"Giovanni Bajo" <giovannibajo@libero.it> writes:

| Hello,
| 
| What does exactly "value-dependent" expression mean, as implemented by
| pt.c:value_dependent_expression_p()?

See standard description at 14.6.2.3.

| I can't fully make it out and it does
| not seem very well documented in the comments. My understanding is that it
| means "an expression whose value depends on a template paramter and thus
| cannot be fully simplified before instantiation". Is this correct?

Nearly but not exactly.

| In this case, I think the code to handle *_CAST_EXPR within
| value_dependent_expression_p is incomplete, because it should also verify if
| the operand of the cast expression is value-dependent or not, as in:
|    /* These expressions are value-dependent if the type to which the
| -     cast occurs is dependent.  */
| +     cast occurs is dependent or the expression being casted is
| +     value-dependent.  */

14.6.2.3/3 handles those:

  Expressions of the following form are value-dependent if either the
  type-id or simple-type-specifier is dependent or the expression or
  cast-expression is value-dependent:

|    if ((TREE_CODE (expression) == DYNAMIC_CAST_EXPR
|         || TREE_CODE (expression) == STATIC_CAST_EXPR
|         || TREE_CODE (expression) == CONST_CAST_EXPR
|         || TREE_CODE (expression) == REINTERPRET_CAST_EXPR
|         || TREE_CODE (expression) == CAST_EXPR)
| -      && dependent_type_p (TREE_TYPE (expression)))
| +      && (dependent_type_p (TREE_TYPE (expression))
| +         || value_dependent_expression_p (TREE_OPERAND (expression, 0))))
|      return true;
| 
| Does this make any sense?

Yes.

| Also, given a template parameter T and auto T t[2], is &t[1] a
| value-dependent expression? 

No.

-- Gaby


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]