]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR c++/50732 ([type_traits] is_base_of<Base, Derived> unnecessarily instantiates...
authorPaolo Carlini <paolo.carlini@oracle.com>
Sat, 15 Oct 2011 19:49:33 +0000 (19:49 +0000)
committerPaolo Carlini <paolo@gcc.gnu.org>
Sat, 15 Oct 2011 19:49:33 +0000 (19:49 +0000)
/cp
2011-10-15  Paolo Carlini  <paolo.carlini@oracle.com>

PR c++/50732
* semantics.c (finish_trait_expr): Do not try to instantiate the
the base type of an __is_base_of trait.
(check_trait_type): Return a tree; use complete_type_or_else.

/testsuite
2011-10-15  Paolo Carlini  <paolo.carlini@oracle.com>

PR c++/50732
* g++.dg/ext/is_base_of_incomplete.C: New.
* g++.dg/ext/is_base_of_diagnostic.C: Adjust dg-errors.
* g++.dg/ext/unary_trait_incomplete.C: Likewise.

From-SVN: r180048

gcc/cp/ChangeLog
gcc/cp/semantics.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/ext/is_base_of_diagnostic.C
gcc/testsuite/g++.dg/ext/is_base_of_incomplete.C [new file with mode: 0644]
gcc/testsuite/g++.dg/ext/unary_trait_incomplete.C

index 09131c589f9c54bda92567f5f71b166d25aa3139..c2c452d2cd5c44edb66ad6ab4444981fcc53eba3 100644 (file)
@@ -1,3 +1,10 @@
+2011-10-15  Paolo Carlini  <paolo.carlini@oracle.com>
+
+       PR c++/50732
+       * semantics.c (finish_trait_expr): Do not try to instantiate the
+       the base type of an __is_base_of trait.
+       (check_trait_type): Return a tree; use complete_type_or_else.
+
 2011-10-14  Jason Merrill  <jason@redhat.com>
 
        PR c++/50563
index 7d37fa3e2c10b8364ce95b1e199cc427f8543fc5..1efe57907b0ce850a8bf49c07a4c6fa0c47f9734 100644 (file)
@@ -5210,23 +5210,20 @@ trait_expr_value (cp_trait_kind kind, tree type1, tree type2)
     }
 }
 
-/* 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, tree type2)
       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, tree type2)
     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:
index cc902504a506b62193af5d54e5ef464bb0c1253e..ce5705ec7ff7e9bf18ab7149d6b3f4d428ebaaf8 100644 (file)
@@ -1,3 +1,10 @@
+2011-10-15  Paolo Carlini  <paolo.carlini@oracle.com>
+
+       PR c++/50732
+       * g++.dg/ext/is_base_of_incomplete.C: New.
+       * g++.dg/ext/is_base_of_diagnostic.C: Adjust dg-errors.
+       * g++.dg/ext/unary_trait_incomplete.C: Likewise.
+
 2011-10-15  Eric Botcazou  <ebotcazou@adacore.com>
 
        * gcc.target/sparc/combined-1.c: Compile at -O2.
index 8cb1ce38f635d2f0f16064d607dcc7c6c1e4f81d..4ccc72b9e943ac22c8cf8802daab797fe080c34b 100644 (file)
@@ -1,7 +1,7 @@
 class A
 { };
 
-class B;
+class B; // { dg-error "forward declaration" }
 
 union C
 { };
diff --git a/gcc/testsuite/g++.dg/ext/is_base_of_incomplete.C b/gcc/testsuite/g++.dg/ext/is_base_of_incomplete.C
new file mode 100644 (file)
index 0000000..4704ff5
--- /dev/null
@@ -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 51cc80cd2ac508e3466de39a0bca2dcb0c962039..ecc5ec224b3002640e5bfe8146ce16c452703c46 100644 (file)
@@ -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" }