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

Doug Gregor doug.gregor@gmail.com
Fri Mar 30 16:46:00 GMT 2007


On 3/30/07, Paolo Carlini <pcarlini@suse.de> wrote:
> Doug Gregor wrote:
>
> > On 3/30/07, Paolo Carlini <pcarlini@suse.de> wrote:
> >
> >> I agree with all your comments and I'm going to do the various changes,
> >> updated patch forthcoming. Only:
> >
> > In cp/tree.c, you should make cp_walk_subtrees walk TRAIT_EXPRs.
>
> Ok, that seems trivial. Can you also provide a testcase for that?

Sure, but it involves variadic templates :)

// { dg-options "-std=gnu++0x" }
template<bool... Bits> struct meta_bitset { };

template<typename... Types>
struct are_classes : meta_bitset<__is_class(Types)...> { };

class X { };
union Y { };

static_assert (__is_base_of(meta_bitset<false, true, false>,
			    are_classes<int, X, Y>),
	       "__is_class failed");

This required two minor fixes. The first was a the aforementioned
change to cp_walk_subtrees:

Index: tree.c
===================================================================
--- tree.c      (revision 123359)
+++ tree.c      (working copy)
@@ -2293,6 +2293,12 @@ cp_walk_subtrees (tree *tp, int *walk_su
       *walk_subtrees_p = 0;
       break;

+    case TRAIT_EXPR:
+      WALK_SUBTREE (TRAIT_EXPR_TYPE1 (*tp));
+      WALK_SUBTREE (TRAIT_EXPR_TYPE2 (*tp));
+      *walk_subtrees_p = 0;
+      break;
+
     default:
       return NULL_TREE;
     }

The second was due to __is_base_of. When it checks that the second
type is complete, it should attempt to complete that type before
failing, like this:

+  /* The only required diagnostic.  */
+  if (kind == CPTK_IS_BASE_OF
+      && NON_UNION_CLASS_TYPE_P (type1) && NON_UNION_CLASS_TYPE_P (type2)
+      && !same_type_ignoring_top_level_qualifiers_p (type1, type2)
+      && !COMPLETE_TYPE_P (complete_type (type2)))
+    {
+      error ("incomplete type %qT not allowed", type2);
+      return error_mark_node;
+    }

  Cheers,
  Doug



More information about the Gcc-patches mailing list