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]

[C++] value-dependent expressions and static_cast


Hello,

What does exactly "value-dependent" expression mean, as implemented by
pt.c:value_dependent_expression_p()? 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?

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.  */
   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?

Also, given a template parameter T and auto T t[2], is &t[1] a
value-dependent expression? Because it looks like it to me, but it's not
recognized as such by the function.

Thanks
Giovanni Bajo


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