[C++ Patch] PR 26099 (first part)

Mark Mitchell mark@codesourcery.com
Fri Mar 30 08:21:00 GMT 2007


Paolo Carlini wrote:

> now that the tree code limit issue is finally solved, as agreed I'm
> sending the first part of the work, leaving out only
> __is_convertible_to, which is going to be much more invasive and tricky.
> Since the last draft I fixed a couple of small bugs (TREE_TYPE not set
> to boolean_type_node in finish_trait_expr; uses_template_parms also
> needs to know about TYPE_EXPRs) and consistently updated/extended the
> testcases.

Yay.

> Tested x86_64-linux, OK for mainline?

Not quite -- but this is very good work, and very close.

> Index: cp/cp-objcp-common.c
> ===================================================================
> --- cp/cp-objcp-common.c	(revision 123155)
> +++ cp/cp-objcp-common.c	(working copy)
> @@ -135,6 +135,8 @@
>      case ARGUMENT_PACK_SELECT:
>        return sizeof (struct tree_argument_pack_select);
>  
> +    case TRAIT_EXPR:		return sizeof (struct tree_trait_expr);
> +

Format on two lines, please.

> +typedef enum cp_trait_kind
> +{
> +  CP_HAS_NOTHROW_ASSIGN,

Use "CPTK_" as the prefix, please.  (CP_Trait_Kind...)

> +/* Nonzero if T is a class type but not an union.  */
> +#define CLASS_TYPE_NON_UNION_P(T) \
> +  (CLASS_TYPE_P (T) && TREE_CODE (T) != UNION_TYPE)

Spell as NON_UNION_CLASS_TYPE_P.  (That's how you'd write it in English:
a "non-union class type".)

> +  unsigned has_complex_dflt_ref : 1;

> +#define TYPE_HAS_COMPLEX_DFLT_REF(NODE) (LANG_TYPE_CLASS_CHECK (NODE)->has_complex_dflt_ref)

Please document.  (I know TYPE_HAS_COMPLEX_INIT_REF is missing this too,
but still...)

> +/* Nonzero for class type means that the default constructor is trivial.  */
> +#define TYPE_HAS_TRIVIAL_DFLT_REF(NODE) \
> +  (TYPE_HAS_DEFAULT_CONSTRUCTOR (NODE) && ! TYPE_HAS_COMPLEX_DFLT_REF (NODE))

Why "REF" is this is about default constructors?  The "REF" in INIT_REF
is because the copy constructor takes an argument of reference type.


> +static bool
> +classtype_has_nothrow_copy_or_assign_p (tree type, bool copy_p)
> +{

> +	  if (t && !TREE_NOTHROW (t))

I think you need to check the exception declaration on the type, not
TREE_NOTHROW.  TREE_NOTHROW may be set by the optimizers when a function
can be proven not to throw, but I assume the standard is talking about
the declared exception specification?

> +      if (trait_expr_value (CP_HAS_TRIVIAL_ASSIGN, type1, type2)
> +	  || (CLASS_TYPE_P (type1)
> +	      && classtype_has_nothrow_copy_or_assign_p (type1, false)))
> +	return true;
> +      break;

Instead of this style, please use:

  return (traits... || (CLASS_TYPE_... && ... ));

?

Please make the parser "sorry" if __is_convertible_to is used, since
it's not implemented yet.

Thanks,

-- 
Mark Mitchell
CodeSourcery
mark@codesourcery.com
(650) 331-3385 x713



More information about the Gcc-patches mailing list