c-ada-spec.h (cpp_operation): Add HAS_DEPENDENT_TEMPLATE_ARGS.
authorPierre-Marie de Rodat <derodat@adacore.com>
Mon, 22 Jun 2015 19:16:58 +0000 (19:16 +0000)
committerEric Botcazou <ebotcazou@gcc.gnu.org>
Mon, 22 Jun 2015 19:16:58 +0000 (19:16 +0000)
c-family/
* c-ada-spec.h (cpp_operation): Add HAS_DEPENDENT_TEMPLATE_ARGS.
* c-ada-spec.c (collect_ada_nodes): Skip NAMESPACE_DECL
(dump_ada_template): Skip partially specialized types.
cp/
* decl2.c (cpp_check): Deal with HAS_DEPENDENT_TEMPLATE_ARGS.

From-SVN: r224754

gcc/c-family/ChangeLog
gcc/c-family/c-ada-spec.c
gcc/c-family/c-ada-spec.h
gcc/cp/ChangeLog
gcc/cp/decl2.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/other/dump-ada-spec-5.C [new file with mode: 0644]
gcc/testsuite/g++.dg/other/dump-ada-spec-6.C [new file with mode: 0644]
gcc/testsuite/g++.dg/other/dump-ada-spec-7.C [new file with mode: 0644]

index 39de58a9ea59b370f76d1c2ca3760fd12fdce3a1..a721ab58183c2f6f01463f42aabb1065c22eb889 100644 (file)
@@ -1,3 +1,9 @@
+2015-06-22  Pierre-Marie de Rodat  <derodat@adacore.com>
+
+       * c-ada-spec.h (cpp_operation): Add HAS_DEPENDENT_TEMPLATE_ARGS.
+       * c-ada-spec.c (collect_ada_nodes): Skip NAMESPACE_DECL
+       (dump_ada_template): Skip partially specialized types.
+
 2015-06-22  Mikhail Maltsev  <maltsevm@gmail.com>
 
        * c-common.c (scalar_to_vector): Use std::swap instead of manually
index 85db5e37dc28aa433e7d62a50e89202d5cfed9ef..ab29f863e4095bad172598dcd215bf0477de2374 100644 (file)
@@ -593,9 +593,12 @@ collect_ada_nodes (tree t, const char *source_file)
   tree n;
   int i = to_dump_count;
 
-  /* Count the likely relevant nodes.  */
+  /* Count the likely relevant nodes: do not dump builtins (they are irrelevant
+     in the context of bindings) and namespaces (we do not handle them properly
+     yet).  */
   for (n = t; n; n = TREE_CHAIN (n))
     if (!DECL_IS_BUILTIN (n)
+       && TREE_CODE (n) != NAMESPACE_DECL
        && LOCATION_FILE (decl_sloc (n, false)) == source_file)
       to_dump_count++;
 
@@ -605,6 +608,7 @@ collect_ada_nodes (tree t, const char *source_file)
   /* Store the relevant nodes.  */
   for (n = t; n; n = TREE_CHAIN (n))
     if (!DECL_IS_BUILTIN (n)
+       && TREE_CODE (n) != NAMESPACE_DECL
        && LOCATION_FILE (decl_sloc (n, false)) == source_file)
       to_dump[i++] = n;
 }
@@ -1745,7 +1749,7 @@ dump_ada_template (pretty_printer *buffer, tree t, int spc)
       != LOCATION_FILE (decl_sloc (t, false)))
     return 0;
 
-  while (inst && inst != error_mark_node)
+  for (; inst && inst != error_mark_node; inst = TREE_CHAIN (inst))
     {
       tree types = TREE_PURPOSE (inst);
       tree instance = TREE_VALUE (inst);
@@ -1756,6 +1760,13 @@ dump_ada_template (pretty_printer *buffer, tree t, int spc)
       if (!RECORD_OR_UNION_TYPE_P (instance) || !TYPE_METHODS (instance))
        break;
 
+      /* We are interested in concrete template instantiations only: skip
+        partially specialized nodes.  */
+      if ((TREE_CODE (instance) == RECORD_TYPE
+          || TREE_CODE (instance) == UNION_TYPE)
+         && cpp_check && cpp_check (instance, HAS_DEPENDENT_TEMPLATE_ARGS))
+       continue;
+
       num_inst++;
       INDENT (spc);
       pp_string (buffer, "package ");
@@ -1791,8 +1802,6 @@ dump_ada_template (pretty_printer *buffer, tree t, int spc)
       pp_semicolon (buffer);
       pp_newline (buffer);
       pp_newline (buffer);
-
-      inst = TREE_CHAIN (inst);
     }
 
   return num_inst > 0;
index 32fcaf91379c7376bfbdbdc23587bfa2ddd1d39f..e922968626fe19c2d56c3987218ce03264867f5d 100644 (file)
@@ -25,6 +25,7 @@ along with GCC; see the file COPYING3.  If not see
 /* In c-ada-spec.c  */
 
 typedef enum {
+  HAS_DEPENDENT_TEMPLATE_ARGS,
   IS_ABSTRACT,
   IS_CONSTRUCTOR,
   IS_DESTRUCTOR,
index 89e43735a05a931ab9db2f492339c0dc61039ca3..f8ad21b17c70faeb8ed7f97107f9646d0478d782 100644 (file)
@@ -1,3 +1,7 @@
+2015-06-22  Pierre-Marie de Rodat  <derodat@adacore.com>
+
+       * decl2.c (cpp_check): Deal with HAS_DEPENDENT_TEMPLATE_ARGS.
+
 2015-06-22  Paolo Carlini  <paolo.carlini@oracle.com>
 
        * decl.c (grokdeclarator): Use declspecs->locations[ds_virtual].
index 8e0eae3745d073569b6067b004e327601dbfb323..e24d2d66c078ad701396ba3f9d5df3a7ce679aea 100644 (file)
@@ -4057,6 +4057,16 @@ cpp_check (tree t, cpp_operation op)
 {
   switch (op)
     {
+      case HAS_DEPENDENT_TEMPLATE_ARGS:
+       {
+         tree ti = CLASSTYPE_TEMPLATE_INFO (t);
+         if (!ti)
+           return 0;
+         ++processing_template_decl;
+         const bool dep = any_dependent_template_arguments_p (TI_ARGS (ti));
+         --processing_template_decl;
+         return dep;
+       }
       case IS_ABSTRACT:
        return DECL_PURE_VIRTUAL_P (t);
       case IS_CONSTRUCTOR:
index 60d13270ff385ab8ebc776dcecd675d9ef2ccb3c..fac610723d2a286d606cf63139523ca3e4076012 100644 (file)
@@ -1,3 +1,9 @@
+2015-06-22  Pierre-Marie de Rodat  <derodat@adacore.com>
+
+       * g++.dg/other/dump-ada-spec-5.C: New test.
+       * g++.dg/other/dump-ada-spec-6.C: Likewise.
+       * g++.dg/other/dump-ada-spec-7.C: Likewise.
+
 2015-06-22  Paolo Carlini  <paolo.carlini@oracle.com>
 
        * g++.dg/inherit/pure1.C: Test location too.
diff --git a/gcc/testsuite/g++.dg/other/dump-ada-spec-5.C b/gcc/testsuite/g++.dg/other/dump-ada-spec-5.C
new file mode 100644 (file)
index 0000000..4a106c5
--- /dev/null
@@ -0,0 +1,11 @@
+/* { dg-do compile } */
+/* { dg-options "-fdump-ada-spec" } */
+
+namespace foo
+{
+  int bar = 0;
+}
+
+namespace bar = foo;
+
+/* { dg-final { cleanup-ada-spec } } */
diff --git a/gcc/testsuite/g++.dg/other/dump-ada-spec-6.C b/gcc/testsuite/g++.dg/other/dump-ada-spec-6.C
new file mode 100644 (file)
index 0000000..9659c50
--- /dev/null
@@ -0,0 +1,23 @@
+/* { dg-do compile } */
+/* { dg-options "-fdump-ada-spec" } */
+
+template<typename T, bool b> class Foo;
+
+template<typename T>
+class Foo<T, false>
+{
+public:
+  // This checks that we do not crash on static members from partially
+  // specialized class templates.
+  static int bar;
+
+  int f();
+};
+
+int func()
+{
+  Foo<int, false> f;
+  return f.f();
+}
+
+/* { dg-final { cleanup-ada-spec } } */
diff --git a/gcc/testsuite/g++.dg/other/dump-ada-spec-7.C b/gcc/testsuite/g++.dg/other/dump-ada-spec-7.C
new file mode 100644 (file)
index 0000000..de47ec3
--- /dev/null
@@ -0,0 +1,24 @@
+/* { dg-do compile } */
+/* { dg-options "-fdump-ada-spec" } */
+
+template<int n>
+void bar ()
+{
+  return;
+}
+
+class Foo
+{
+  // This check that we properly skip the specification for templated
+  // members of non-templated classes.
+  template<int n>
+  void bar ();
+};
+
+template<int n>
+void Foo::bar ()
+{
+  return;
+}
+
+/* { dg-final { cleanup-ada-spec } } */