This is the mail archive of the
mailing list for the GCC project.
Re: C++ PATCH for constexpr
- From: Jason Merrill <jason at redhat dot com>
- To: Gabriel Dos Reis <gdr at cs dot tamu dot edu>
- Cc: bkoz at redhat dot com, gcc-patches at gcc dot gnu dot org
- Date: Sun, 29 Nov 2009 01:09:04 -0500
- Subject: Re: C++ PATCH for constexpr
- References: <email@example.com>
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. */
+#define COMPILE_TIME_CONSTANT_P(NODE) \
+ (TREE_LANG_FLAG_7 (NODE))
+/* 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. */
+#define VALID_FOR_STATIC_INITIALIZATION_P(NODE) \
+ (CONSTANT_CLASS_P (NODE) || COMPILE_TIME_CONSTANT_P (NODE))
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
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:
+ if (AGGR_INIT_VIA_CTOR_P (t) && !CLASSTYPE_LITERAL_P (TREE_TYPE (t)))
+ 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?