Add psymbols for nested types

Message ID 20180323180822.25737-1-keiths@redhat.com
State New, archived
Headers

Commit Message

Keith Seitz March 23, 2018, 6:08 p.m. UTC
  c++/22968 involves the inability of ptype to find a type definition for
a type defined inside another type.  I recently added some additional
support for nested type definitions, but I apparently overlooked psymbols.

The user reports that using -readnow fixes the problem:

$ gdb 22968 -ex "ptype Outer::Inner"
There is no field named Inner

$ gdb -readnow 22968 -ex "ptype Outer::Inner"
type = struct Outer::Inner {
  <no data field>
}

We clearly did not find a psymbol for Outer::Inner because it was located
in another CU.  This patch addresses this problem by scanning structs
for additional psymbols.  Rust is already doing this.

With this patch, the identical result to "-readnow" is given (without
using `-readnow', of course).

gdb/ChangeLog:

	PR c++/22968
	* dwarf2read.c (scan_partial_symbols): Scan structs/classes for
	nested type definitions for C++, too.

gdb/testsuite/ChangeLog:

	PR c++/22968
	* gdb.cp/subtypes.exp: New file.
	* gdb.cp/subtypes.h: New file.
	* gdb.cp/subtypes.cc: New file.
	* gdb.cp/subtypes-2.cc: New file.
---
 gdb/ChangeLog                      |  6 +++++
 gdb/dwarf2read.c                   |  3 ++-
 gdb/testsuite/ChangeLog            |  8 ++++++
 gdb/testsuite/gdb.cp/subtypes-2.cc | 30 ++++++++++++++++++++++
 gdb/testsuite/gdb.cp/subtypes.cc   | 42 ++++++++++++++++++++++++++++++
 gdb/testsuite/gdb.cp/subtypes.exp  | 52 ++++++++++++++++++++++++++++++++++++++
 gdb/testsuite/gdb.cp/subtypes.h    | 50 ++++++++++++++++++++++++++++++++++++
 7 files changed, 190 insertions(+), 1 deletion(-)
 create mode 100644 gdb/testsuite/gdb.cp/subtypes-2.cc
 create mode 100644 gdb/testsuite/gdb.cp/subtypes.cc
 create mode 100644 gdb/testsuite/gdb.cp/subtypes.exp
 create mode 100644 gdb/testsuite/gdb.cp/subtypes.h
  

Comments

Pedro Alves March 23, 2018, 6:22 p.m. UTC | #1
Looks good, please push.

Does this work with a gdb index instead of psymbols?
I.e., does the test pass with --target_board=dwarf4-gdb-index ?

Thanks,
Pedro Alves

On 03/23/2018 06:08 PM, Keith Seitz wrote:
> c++/22968 involves the inability of ptype to find a type definition for
> a type defined inside another type.  I recently added some additional
> support for nested type definitions, but I apparently overlooked psymbols.
> 
> The user reports that using -readnow fixes the problem:
> 
> $ gdb 22968 -ex "ptype Outer::Inner"
> There is no field named Inner
> 
> $ gdb -readnow 22968 -ex "ptype Outer::Inner"
> type = struct Outer::Inner {
>   <no data field>
> }
> 
> We clearly did not find a psymbol for Outer::Inner because it was located
> in another CU.  This patch addresses this problem by scanning structs
> for additional psymbols.  Rust is already doing this.
> 
> With this patch, the identical result to "-readnow" is given (without
> using `-readnow', of course).
> 
> gdb/ChangeLog:
> 
> 	PR c++/22968
> 	* dwarf2read.c (scan_partial_symbols): Scan structs/classes for
> 	nested type definitions for C++, too.
> 
> gdb/testsuite/ChangeLog:
> 
> 	PR c++/22968
> 	* gdb.cp/subtypes.exp: New file.
> 	* gdb.cp/subtypes.h: New file.
> 	* gdb.cp/subtypes.cc: New file.
> 	* gdb.cp/subtypes-2.cc: New file.
> ---
>  gdb/ChangeLog                      |  6 +++++
>  gdb/dwarf2read.c                   |  3 ++-
>  gdb/testsuite/ChangeLog            |  8 ++++++
>  gdb/testsuite/gdb.cp/subtypes-2.cc | 30 ++++++++++++++++++++++
>  gdb/testsuite/gdb.cp/subtypes.cc   | 42 ++++++++++++++++++++++++++++++
>  gdb/testsuite/gdb.cp/subtypes.exp  | 52 ++++++++++++++++++++++++++++++++++++++
>  gdb/testsuite/gdb.cp/subtypes.h    | 50 ++++++++++++++++++++++++++++++++++++
>  7 files changed, 190 insertions(+), 1 deletion(-)
>  create mode 100644 gdb/testsuite/gdb.cp/subtypes-2.cc
>  create mode 100644 gdb/testsuite/gdb.cp/subtypes.cc
>  create mode 100644 gdb/testsuite/gdb.cp/subtypes.exp
>  create mode 100644 gdb/testsuite/gdb.cp/subtypes.h
> 
> diff --git a/gdb/ChangeLog b/gdb/ChangeLog
> index 2226e42bc2..744c0b1bfc 100644
> --- a/gdb/ChangeLog
> +++ b/gdb/ChangeLog
> @@ -1,3 +1,9 @@
> +2018-MM-DD  Keith Seitz  <keiths@redhat.com>
> +
> +	PR c++/22968
> +	* dwarf2read.c (scan_partial_symbols): Scan structs/classes for
> +	nested type definitions for C++, too.
> +
>  2018-03-23  Tom Tromey  <tom@tromey.com>
>  
>  	* machoread.c (struct oso_el): Add a constructor.  Don't define as
> diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c
> index 6100438049..93ecf407e3 100644
> --- a/gdb/dwarf2read.c
> +++ b/gdb/dwarf2read.c
> @@ -9116,7 +9116,8 @@ scan_partial_symbols (struct partial_die_info *first_die, CORE_ADDR *lowpc,
>  		{
>  		  add_partial_symbol (pdi, cu);
>  		}
> -	      if (cu->language == language_rust && pdi->has_children)
> +	      if ((cu->language == language_rust
> +		   || cu->language == language_cplus) && pdi->has_children)
>  		scan_partial_symbols (pdi->die_child, lowpc, highpc,
>  				      set_addrmap, cu);
>  	      break;
> diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog
> index 1412c689da..96624efe72 100644
> --- a/gdb/testsuite/ChangeLog
> +++ b/gdb/testsuite/ChangeLog
> @@ -1,3 +1,11 @@
> +2018-MM-DD  Keith Seitz  <keiths@redhat.com>
> +
> +	PR c++/22968
> +	* gdb.cp/subtypes.exp: New file.
> +	* gdb.cp/subtypes.h: New file.
> +	* gdb.cp/subtypes.cc: New file.
> +	* gdb.cp/subtypes-2.cc: New file.
> +
>  2018-03-23  Andrew Burgess  <andrew.burgess@embecosm.com>
>  
>  	* gdb.arch/amd64-disp-step-avx.S: Add '_start' label.
> diff --git a/gdb/testsuite/gdb.cp/subtypes-2.cc b/gdb/testsuite/gdb.cp/subtypes-2.cc
> new file mode 100644
> index 0000000000..3426443a4d
> --- /dev/null
> +++ b/gdb/testsuite/gdb.cp/subtypes-2.cc
> @@ -0,0 +1,30 @@
> +/* This testcase is part of GDB, the GNU debugger.
> +
> +   Copyright 2018 Free Software Foundation, Inc.
> +
> +   This program is free software; you can redistribute it and/or modify
> +   it under the terms of the GNU General Public License as published by
> +   the Free Software Foundation; either version 3 of the License, or
> +   (at your option) any later version.
> +
> +   This program is distributed in the hope that it will be useful,
> +   but WITHOUT ANY WARRANTY; without even the implied warranty of
> +   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> +   GNU General Public License for more details.
> +
> +   You should have received a copy of the GNU General Public License
> +   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
> +
> +#include "subtypes.h"
> +
> +struct Outer::Inner
> +{
> +  int doit () { return 1; }
> +  struct InnerInner {} p;
> +  int a;
> +};
> +
> +Outer::Outer (): p (new Inner), e (Oenum::OC)
> +{
> +  p->a = p->doit ();
> +}
> diff --git a/gdb/testsuite/gdb.cp/subtypes.cc b/gdb/testsuite/gdb.cp/subtypes.cc
> new file mode 100644
> index 0000000000..e95490c8b0
> --- /dev/null
> +++ b/gdb/testsuite/gdb.cp/subtypes.cc
> @@ -0,0 +1,42 @@
> +/* This testcase is part of GDB, the GNU debugger.
> +
> +   Copyright 2018 Free Software Foundation, Inc.
> +
> +   This program is free software; you can redistribute it and/or modify
> +   it under the terms of the GNU General Public License as published by
> +   the Free Software Foundation; either version 3 of the License, or
> +   (at your option) any later version.
> +
> +   This program is distributed in the hope that it will be useful,
> +   but WITHOUT ANY WARRANTY; without even the implied warranty of
> +   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> +   GNU General Public License for more details.
> +
> +   You should have received a copy of the GNU General Public License
> +   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
> +
> +#include "subtypes.h"
> +
> +int
> +main (int argc, char *argv[])
> +{
> +  struct Foo
> +  {
> +    int doit (void) { return 1111; }
> +  } foo;
> +
> +  struct Bar
> +  {
> +    int doit (void) { return 2222; }
> +  } bar;
> +
> +  struct Baz
> +  {
> +    int doit (void) { return 3333; }
> +  } baz;
> +  Outer o;
> +  o.e = Outer::Oenum::OA;
> +
> +  return foo.doit () + bar.doit () + baz.doit () + foobar<int> (6)
> +    + foobar<char> ('c');
> +}
> diff --git a/gdb/testsuite/gdb.cp/subtypes.exp b/gdb/testsuite/gdb.cp/subtypes.exp
> new file mode 100644
> index 0000000000..6c5f7f845c
> --- /dev/null
> +++ b/gdb/testsuite/gdb.cp/subtypes.exp
> @@ -0,0 +1,52 @@
> +# Copyright 2018 Free Software Foundation, Inc.
> +
> +# This program is free software; you can redistribute it and/or modify
> +# it under the terms of the GNU General Public License as published by
> +# the Free Software Foundation; either version 3 of the License, or
> +# (at your option) any later version.
> +#
> +# This program is distributed in the hope that it will be useful,
> +# but WITHOUT ANY WARRANTY; without even the implied warranty of
> +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> +# GNU General Public License for more details.
> +#
> +# You should have received a copy of the GNU General Public License
> +# along with this program.  If not, see <http://www.gnu.org/licenses/>.
> +
> +# Test for subtype definitions, i.e., types defined in classes, functions,
> +# etc.
> +
> +if {[skip_cplus_tests]} { continue }
> +
> +load_lib "cp-support.exp"
> +
> +standard_testfile .cc subtypes-2.cc
> +
> +if {[prepare_for_testing "failed to prepare" $testfile \
> +	 [list $srcfile $srcfile2] {debug c++}]} {
> +    return -1
> +}
> +
> +gdb_test "ptype Outer::Inner::InnerInner" \
> +    "type = struct Outer::Inner::InnerInner.*"
> +gdb_test "ptype Outer::Inner" "type = struct Outer::Inner.*"
> +gdb_test "ptype main::Foo" "type = struct Foo.*"
> +gdb_test "ptype main::Bar" "type = struct Bar.*"
> +gdb_test "ptype main::Baz" "type = struct Baz.*"
> +gdb_test "ptype Outer::Oenum" "type = enum class Outer::Oenum.*"
> +gdb_test "ptype foobar<int>::Foo" "type = struct Foo.*"
> +gdb_test "ptype foobar<int>::Bar" "type = struct Bar.*"
> +gdb_test "ptype foobar<int>::Baz" "type = struct Baz.*"
> +gdb_test "ptype foobar<char>::Foo" "type = struct Foo.*"
> +gdb_test "ptype foobar<char>::Bar" "type = struct Bar.*"
> +gdb_test "ptype foobar<char>::Baz" "type = struct Baz.*"
> +gdb_breakpoint "Outer::Inner::doit" message
> +gdb_breakpoint "main::Foo::doit" message
> +gdb_breakpoint "main::Bar::doit" message
> +gdb_breakpoint "main::Baz::doit" message
> +gdb_breakpoint "foobar<int>(int)::Foo::doit" message
> +gdb_breakpoint "foobar<int>(int)::Bar::doit" message
> +gdb_breakpoint "foobar<int>(int)::Baz::doit" message
> +gdb_breakpoint "foobar<char>(int)::Foo::doit" message
> +gdb_breakpoint "foobar<char>(int)::Bar::doit" message
> +gdb_breakpoint "foobar<char>(int)::Baz::doit" message
> diff --git a/gdb/testsuite/gdb.cp/subtypes.h b/gdb/testsuite/gdb.cp/subtypes.h
> new file mode 100644
> index 0000000000..5f29c2674e
> --- /dev/null
> +++ b/gdb/testsuite/gdb.cp/subtypes.h
> @@ -0,0 +1,50 @@
> +/* This testcase is part of GDB, the GNU debugger.
> +
> +   Copyright 2018 Free Software Foundation, Inc.
> +
> +   This program is free software; you can redistribute it and/or modify
> +   it under the terms of the GNU General Public License as published by
> +   the Free Software Foundation; either version 3 of the License, or
> +   (at your option) any later version.
> +
> +   This program is distributed in the hope that it will be useful,
> +   but WITHOUT ANY WARRANTY; without even the implied warranty of
> +   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> +   GNU General Public License for more details.
> +
> +   You should have received a copy of the GNU General Public License
> +   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
> +
> +/* A template that defines subtypes.  */
> +
> +template <typename T>
> +T foobar (int arg)
> +{
> +  struct Foo
> +  {
> +    T doit (void) { return 1; }
> +  } foo;
> +
> +  struct Bar
> +  {
> +    T doit (void) { return 2; }
> +  } bar;
> +
> +  struct Baz
> +  {
> +    T doit (void) { return 3; }
> +  } baz;
> +
> +  return arg - foo.doit () - bar.doit () - baz.doit ();
> +}
> +
> +/* A structure that defines other types.  */
> +
> +struct Outer
> +{
> +  enum class Oenum { OA, OB, OC, OD };
> +  struct Inner;
> +  Inner *p;
> +  Oenum e;
> +  Outer ();
> +};
>
  
Keith Seitz March 23, 2018, 6:59 p.m. UTC | #2
On 03/23/2018 11:22 AM, Pedro Alves wrote:
> Looks good, please push.
> 
> Does this work with a gdb index instead of psymbols?
> I.e., does the test pass with --target_board=dwarf4-gdb-index ?
> 

Yes, it does:

		=== gdb tests ===

Schedule of variations:
    dwarf4-gdb-index

Running target dwarf4-gdb-index
Using /home/keiths/work/gdb/branches/virgin/linux/gdb/testsuite/../../../src/gdb/testsuite/boards/../boards/dwarf4-gdb-index.exp as board description file for target.
Using /home/keiths/work/gdb/branches/virgin/linux/gdb/testsuite/../../../src/gdb/testsuite/boards/../boards/local-board.exp as board description file for target.
Using /usr/share/dejagnu/config/unix.exp as generic interface file for target.
Using /home/keiths/work/gdb/branches/virgin/linux/gdb/testsuite/../../../src/gdb/testsuite/config/unix.exp as tool-and-target-specific interface file.
Running /home/keiths/work/gdb/branches/virgin/linux/gdb/testsuite/../../../src/gdb/testsuite/gdb.cp/subtypes.exp ...

		=== gdb Summary ===

# of expected passes		22


Pushed. Thank you for taking a look.

Keith
  

Patch

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 2226e42bc2..744c0b1bfc 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,9 @@ 
+2018-MM-DD  Keith Seitz  <keiths@redhat.com>
+
+	PR c++/22968
+	* dwarf2read.c (scan_partial_symbols): Scan structs/classes for
+	nested type definitions for C++, too.
+
 2018-03-23  Tom Tromey  <tom@tromey.com>
 
 	* machoread.c (struct oso_el): Add a constructor.  Don't define as
diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c
index 6100438049..93ecf407e3 100644
--- a/gdb/dwarf2read.c
+++ b/gdb/dwarf2read.c
@@ -9116,7 +9116,8 @@  scan_partial_symbols (struct partial_die_info *first_die, CORE_ADDR *lowpc,
 		{
 		  add_partial_symbol (pdi, cu);
 		}
-	      if (cu->language == language_rust && pdi->has_children)
+	      if ((cu->language == language_rust
+		   || cu->language == language_cplus) && pdi->has_children)
 		scan_partial_symbols (pdi->die_child, lowpc, highpc,
 				      set_addrmap, cu);
 	      break;
diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog
index 1412c689da..96624efe72 100644
--- a/gdb/testsuite/ChangeLog
+++ b/gdb/testsuite/ChangeLog
@@ -1,3 +1,11 @@ 
+2018-MM-DD  Keith Seitz  <keiths@redhat.com>
+
+	PR c++/22968
+	* gdb.cp/subtypes.exp: New file.
+	* gdb.cp/subtypes.h: New file.
+	* gdb.cp/subtypes.cc: New file.
+	* gdb.cp/subtypes-2.cc: New file.
+
 2018-03-23  Andrew Burgess  <andrew.burgess@embecosm.com>
 
 	* gdb.arch/amd64-disp-step-avx.S: Add '_start' label.
diff --git a/gdb/testsuite/gdb.cp/subtypes-2.cc b/gdb/testsuite/gdb.cp/subtypes-2.cc
new file mode 100644
index 0000000000..3426443a4d
--- /dev/null
+++ b/gdb/testsuite/gdb.cp/subtypes-2.cc
@@ -0,0 +1,30 @@ 
+/* This testcase is part of GDB, the GNU debugger.
+
+   Copyright 2018 Free Software Foundation, Inc.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+#include "subtypes.h"
+
+struct Outer::Inner
+{
+  int doit () { return 1; }
+  struct InnerInner {} p;
+  int a;
+};
+
+Outer::Outer (): p (new Inner), e (Oenum::OC)
+{
+  p->a = p->doit ();
+}
diff --git a/gdb/testsuite/gdb.cp/subtypes.cc b/gdb/testsuite/gdb.cp/subtypes.cc
new file mode 100644
index 0000000000..e95490c8b0
--- /dev/null
+++ b/gdb/testsuite/gdb.cp/subtypes.cc
@@ -0,0 +1,42 @@ 
+/* This testcase is part of GDB, the GNU debugger.
+
+   Copyright 2018 Free Software Foundation, Inc.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+#include "subtypes.h"
+
+int
+main (int argc, char *argv[])
+{
+  struct Foo
+  {
+    int doit (void) { return 1111; }
+  } foo;
+
+  struct Bar
+  {
+    int doit (void) { return 2222; }
+  } bar;
+
+  struct Baz
+  {
+    int doit (void) { return 3333; }
+  } baz;
+  Outer o;
+  o.e = Outer::Oenum::OA;
+
+  return foo.doit () + bar.doit () + baz.doit () + foobar<int> (6)
+    + foobar<char> ('c');
+}
diff --git a/gdb/testsuite/gdb.cp/subtypes.exp b/gdb/testsuite/gdb.cp/subtypes.exp
new file mode 100644
index 0000000000..6c5f7f845c
--- /dev/null
+++ b/gdb/testsuite/gdb.cp/subtypes.exp
@@ -0,0 +1,52 @@ 
+# Copyright 2018 Free Software Foundation, Inc.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+# Test for subtype definitions, i.e., types defined in classes, functions,
+# etc.
+
+if {[skip_cplus_tests]} { continue }
+
+load_lib "cp-support.exp"
+
+standard_testfile .cc subtypes-2.cc
+
+if {[prepare_for_testing "failed to prepare" $testfile \
+	 [list $srcfile $srcfile2] {debug c++}]} {
+    return -1
+}
+
+gdb_test "ptype Outer::Inner::InnerInner" \
+    "type = struct Outer::Inner::InnerInner.*"
+gdb_test "ptype Outer::Inner" "type = struct Outer::Inner.*"
+gdb_test "ptype main::Foo" "type = struct Foo.*"
+gdb_test "ptype main::Bar" "type = struct Bar.*"
+gdb_test "ptype main::Baz" "type = struct Baz.*"
+gdb_test "ptype Outer::Oenum" "type = enum class Outer::Oenum.*"
+gdb_test "ptype foobar<int>::Foo" "type = struct Foo.*"
+gdb_test "ptype foobar<int>::Bar" "type = struct Bar.*"
+gdb_test "ptype foobar<int>::Baz" "type = struct Baz.*"
+gdb_test "ptype foobar<char>::Foo" "type = struct Foo.*"
+gdb_test "ptype foobar<char>::Bar" "type = struct Bar.*"
+gdb_test "ptype foobar<char>::Baz" "type = struct Baz.*"
+gdb_breakpoint "Outer::Inner::doit" message
+gdb_breakpoint "main::Foo::doit" message
+gdb_breakpoint "main::Bar::doit" message
+gdb_breakpoint "main::Baz::doit" message
+gdb_breakpoint "foobar<int>(int)::Foo::doit" message
+gdb_breakpoint "foobar<int>(int)::Bar::doit" message
+gdb_breakpoint "foobar<int>(int)::Baz::doit" message
+gdb_breakpoint "foobar<char>(int)::Foo::doit" message
+gdb_breakpoint "foobar<char>(int)::Bar::doit" message
+gdb_breakpoint "foobar<char>(int)::Baz::doit" message
diff --git a/gdb/testsuite/gdb.cp/subtypes.h b/gdb/testsuite/gdb.cp/subtypes.h
new file mode 100644
index 0000000000..5f29c2674e
--- /dev/null
+++ b/gdb/testsuite/gdb.cp/subtypes.h
@@ -0,0 +1,50 @@ 
+/* This testcase is part of GDB, the GNU debugger.
+
+   Copyright 2018 Free Software Foundation, Inc.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+/* A template that defines subtypes.  */
+
+template <typename T>
+T foobar (int arg)
+{
+  struct Foo
+  {
+    T doit (void) { return 1; }
+  } foo;
+
+  struct Bar
+  {
+    T doit (void) { return 2; }
+  } bar;
+
+  struct Baz
+  {
+    T doit (void) { return 3; }
+  } baz;
+
+  return arg - foo.doit () - bar.doit () - baz.doit ();
+}
+
+/* A structure that defines other types.  */
+
+struct Outer
+{
+  enum class Oenum { OA, OB, OC, OD };
+  struct Inner;
+  Inner *p;
+  Oenum e;
+  Outer ();
+};