On 10/15/2011 08:33 PM, Jason Merrill wrote:
On 10/14/2011 06:57 PM, Paolo Carlini wrote:
-  return false;
+  return complete_type_or_else (type, NULL_TREE);

I think I'd do

  complete_type_or_else (strip_array_types (type), NULL_TREE)

so that the error doesn't complain about unspecified bounds, which would be misleading.
Good point, thanks.

Thus, what about the below? Again, testing already past g++.dg/dg.exp.

Thanks again,
Paolo.

///////////////////////
Index: testsuite/g++.dg/ext/unary_trait_incomplete.C
===================================================================
--- testsuite/g++.dg/ext/unary_trait_incomplete.C       (revision 180046)
+++ testsuite/g++.dg/ext/unary_trait_incomplete.C       (working copy)
@@ -1,6 +1,6 @@
 // PR c++/39475
 
-struct I;
+struct I; // { dg-error "forward declaration" }
 struct C { };
 
 bool nas1 = __has_nothrow_assign(I); // { dg-error "incomplete type" }
Index: testsuite/g++.dg/ext/is_base_of_diagnostic.C
===================================================================
--- testsuite/g++.dg/ext/is_base_of_diagnostic.C        (revision 180046)
+++ testsuite/g++.dg/ext/is_base_of_diagnostic.C        (working copy)
@@ -1,7 +1,7 @@
 class A
 { };
 
-class B;
+class B; // { dg-error "forward declaration" }
 
 union C
 { };
Index: testsuite/g++.dg/ext/is_base_of_incomplete.C
===================================================================
--- testsuite/g++.dg/ext/is_base_of_incomplete.C        (revision 0)
+++ testsuite/g++.dg/ext/is_base_of_incomplete.C        (revision 0)
@@ -0,0 +1,9 @@
+// PR c++/50732
+
+template <typename T>
+struct non_instantiable
+{
+  typedef typename T::THIS_TYPE_CANNOT_BE_INSTANTIATED type;
+};
+
+int check[__is_base_of(non_instantiable<int>, void) ? -1 : 1];
Index: cp/semantics.c
===================================================================
--- cp/semantics.c      (revision 180007)
+++ cp/semantics.c      (working copy)
@@ -5210,23 +5210,20 @@ trait_expr_value (cp_trait_kind kind, tree type1,
     }
 }
 
-/* Returns true if TYPE is a complete type, an array of unknown bound,
-   or (possibly cv-qualified) void, returns false otherwise.  */
+/* If TYPE is an array of unknown bound, or (possibly cv-qualified)
+   void, or a complete type, returns it, otherwise NULL_TREE.  */
 
-static bool
+static tree
 check_trait_type (tree type)
 {
-  if (COMPLETE_TYPE_P (type))
-    return true;
-
   if (TREE_CODE (type) == ARRAY_TYPE && !TYPE_DOMAIN (type)
       && COMPLETE_TYPE_P (TREE_TYPE (type)))
-    return true;
+    return type;
 
   if (VOID_TYPE_P (type))
-    return true;
+    return type;
 
-  return false;
+  return complete_type_or_else (strip_array_types (type), NULL_TREE);
 }
 
 /* Process a trait expression.  */
@@ -5276,10 +5273,6 @@ finish_trait_expr (cp_trait_kind kind, tree type1,
       return trait_expr;
     }
 
-  complete_type (type1);
-  if (type2)
-    complete_type (type2);
-
   switch (kind)
     {
     case CPTK_HAS_NOTHROW_ASSIGN:
@@ -5298,20 +5291,15 @@ finish_trait_expr (cp_trait_kind kind, tree type1,
     case CPTK_IS_STD_LAYOUT:
     case CPTK_IS_TRIVIAL:
       if (!check_trait_type (type1))
-       {
-         error ("incomplete type %qT not allowed", type1);
-         return error_mark_node;
-       }
+       return error_mark_node;
       break;
 
     case CPTK_IS_BASE_OF:
       if (NON_UNION_CLASS_TYPE_P (type1) && NON_UNION_CLASS_TYPE_P (type2)
          && !same_type_ignoring_top_level_qualifiers_p (type1, type2)
-         && !COMPLETE_TYPE_P (type2))
-       {
-         error ("incomplete type %qT not allowed", type2);
-         return error_mark_node;
-       }
+         && !complete_type_or_else (type2, NULL_TREE))
+       /* We already issued an error.  */
+       return error_mark_node;
       break;
 
     case CPTK_IS_CLASS:

Reply via email to