This is the mail archive of the 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++ PATCH for constexpr

On 11/26/2009 08:39 PM, Gabriel Dos Reis wrote:
I do not know exactly what to do with __builtin_xxx functions when
testing whether an expression is a potential constant expressions or
not.   When and how GCC fold those expressions depend on commandlines...

I'd allow them if GCC ever folds them to a constant. If a particular call isn't folded to a constant, we can give an error at that point.

+/* True if the expression tree NODE represents an object that can
+   be taken apart at compile time.  This is not to be confused with
+   link-time constants or load-time constants.  A compiler constant
+   may still be an expression that the middle end may be able to
+   reduce further.  */
+/* Same as COMPILE_TIME_CONSTANT_P, except that it includes literal
+   values too, such as INTEGER_CST, PTRMEM_CST, or address of
+   variables with static storage.  */

Your first comment seems a bit off. The address of a variable with static storage duration is a load-time constant; at compile time we don't know the numeric address, so it's a symbolic reference. What link-time or load-time constants do you mean to exclude?

Also, it seems that COMPILE_TIME_CONSTANT_P is only getting set on CONSTRUCTOR nodes (not ADDR_EXPR of TREE_STATIC decls); if you make it specific to CONSTRUCTORs we don't need a new TREE_LANG_FLAG. Maybe LITERAL_CONSTRUCTOR_P?

Or, better, can we just make VALID_FOR_STATIC_INITIALIZATION_P a function that knows to descend into CONSTRUCTORs so we don't need a flag at all? It seems like potential_constant_expression might already be that function if you add a flag to control the special parm handling.

+    case AGGR_INIT_EXPR:
+        {
+          error ("object of non-literal type is not potential constant");
+          return false;
+        }

I don't think we need any special code for AGGR_INIT_EXPR. If the function is a constructor for a non-literal class, the constructor won't be constexpr, so we'll complain later.

+            if (i == 0 && DECL_NONSTATIC_MEMBER_P (fun)
+                && (TREE_CODE (t) != AGGR_INIT_EXPR
+                    || !AGGR_INIT_VIA_CTOR_P (t)))


if (i == 0 && DECL_NONSTATIC_MEMBER_P (fun)
    && !DECL_CONSTRUCTOR_P (fun))


+  for (b = call->bindings; b != NULL; b = TREE_CHAIN (b))
+    if (TREE_PURPOSE (b) == t)
+      return TREE_VALUE (b);

Weren't you going to use purpose_value here?


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