===================================================================
@@ -1,7 +1,7 @@
class A
{ };
-class B;
+class B; // { dg-error "forward declaration" }
union C
{ };
===================================================================
@@ -0,0 +1,7 @@
+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];
===================================================================
@@ -5276,10 +5276,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:
@@ -5297,9 +5293,10 @@ finish_trait_expr (cp_trait_kind kind, tree type1,
case CPTK_IS_POLYMORPHIC:
case CPTK_IS_STD_LAYOUT:
case CPTK_IS_TRIVIAL:
+ complete_type (type1);
if (!check_trait_type (type1))
{
- error ("incomplete type %qT not allowed", type1);
+ error ("invalid use of incomplete type %qT", type1);
return error_mark_node;
}
break;
@@ -5307,11 +5304,9 @@ finish_trait_expr (cp_trait_kind kind, tree type1,
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:
On 10/14/2011 09:08 PM, Jason Merrill wrote: > How about using complete_type_or_else? The CPTK_IS_BASE_OF case becomes much simpler indeed, thanks. For the unary traits, though, I don't see an advantage in using it, because in some cases in check_trait_type we don't want to error out even when complete_type_or_else would. Unless we can check whether we are dealing with an array of unknown bound *before* completing the type? That is: if (TREE_CODE (type) == ARRAY_TYPE && !TYPE_DOMAIN (type) && COMPLETE_TYPE_P (TREE_TYPE (type))) is the outcome always the same before and after trying to complete (type)? Thanks, Paolo. //////////////////////