Pass -Wno-deprecated-register for gdb.cp that use "register"
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.cp / classes.exp
index ae43630a1c263ae01e73ebb994ae8da85faf3f0a..4a2287a8704f410b2e3a4e84b9ed7536755f3df6 100644 (file)
@@ -1,4 +1,4 @@
-# Copyright 1992, 1994-2004, 2006-2012 Free Software Foundation, Inc.
+# Copyright 1992-2020 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
@@ -22,13 +22,11 @@ if { [skip_cplus_tests] } { continue }
 
 load_lib "cp-support.exp"
 
-set testfile "classes"
-set srcfile ${testfile}.cc
-set binfile ${objdir}/${subdir}/${testfile}
+standard_testfile .cc
 
-if  { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug c++}] != "" } {
-     untested classes.exp
-     return -1
+if {[prepare_for_testing "failed to prepare" $testfile $srcfile \
+        {debug c++ additional_flags=-Wno-deprecated-register}]} {
+    return -1
 }
 
 # Test ptype of class objects.
@@ -38,7 +36,7 @@ proc test_ptype_class_objects {} {
     # Simple type.
 
     cp_test_ptype_class \
-       "ptype struct default_public_struct" "" "struct" "default_public_struct" \
+       "struct default_public_struct" "" "struct" "default_public_struct" \
        {
            { field public "int a;" }
            { field public "int b;" }
@@ -47,7 +45,7 @@ proc test_ptype_class_objects {} {
     # Another simple type.
 
     cp_test_ptype_class \
-       "ptype struct explicit_public_struct" "" "struct" "explicit_public_struct" \
+       "struct explicit_public_struct" "" "struct" "explicit_public_struct" \
        {
            { field public "int a;" }
            { field public "int b;" }
@@ -56,7 +54,7 @@ proc test_ptype_class_objects {} {
     # Another simple type.
 
     cp_test_ptype_class \
-       "ptype struct protected_struct" "" "struct" "protected_struct" \
+       "struct protected_struct" "" "struct" "protected_struct" \
        {
            { field protected "int a;" }
            { field protected "int b;" }
@@ -65,7 +63,7 @@ proc test_ptype_class_objects {} {
     # Another simple type.
 
     cp_test_ptype_class \
-       "ptype struct private_struct" "" "struct" "private_struct" \
+       "struct private_struct" "" "struct" "private_struct" \
        {
            { field private "int a;" }
            { field private "int b;" }
@@ -74,7 +72,7 @@ proc test_ptype_class_objects {} {
     # A bigger type.
 
     cp_test_ptype_class \
-       "ptype struct mixed_protection_struct" "" "struct" "mixed_protection_struct" \
+       "struct mixed_protection_struct" "" "struct" "mixed_protection_struct" \
        {
            { field public    "int a;" }
            { field public    "int b;" }
@@ -91,7 +89,7 @@ proc test_ptype_class_objects {} {
     # gdb does not care about the difference anyways.
 
     cp_test_ptype_class \
-       "ptype class public_class" "" "class" "public_class" \
+       "class public_class" "" "class" "public_class" \
        {
            { field public "int a;" }
            { field public "int b;" }
@@ -100,7 +98,7 @@ proc test_ptype_class_objects {} {
     # Another simple type.
 
     cp_test_ptype_class \
-       "ptype class protected_class" "" "class" "protected_class" \
+       "class protected_class" "" "class" "protected_class" \
        {
            { field protected "int a;" }
            { field protected "int b;" }
@@ -109,7 +107,7 @@ proc test_ptype_class_objects {} {
     # Another simple type.
 
     cp_test_ptype_class \
-       "ptype class default_private_class" "" "class" "default_private_class" \
+       "class default_private_class" "" "class" "default_private_class" \
        {
            { field private "int a;" }
            { field private "int b;" }
@@ -118,7 +116,7 @@ proc test_ptype_class_objects {} {
     # Another simple type.
 
     cp_test_ptype_class \
-       "ptype class explicit_private_class" "" "class" "explicit_private_class" \
+       "class explicit_private_class" "" "class" "explicit_private_class" \
        {
            { field private "int a;" }
            { field private "int b;" }
@@ -127,7 +125,7 @@ proc test_ptype_class_objects {} {
     # A bigger type.
 
     cp_test_ptype_class \
-       "ptype class mixed_protection_class" "" "class" "mixed_protection_class" \
+       "class mixed_protection_class" "" "class" "mixed_protection_class" \
        {
 
            { field public    "int a;" }
@@ -146,7 +144,7 @@ proc test_ptype_class_objects {} {
     # Base class.
 
     cp_test_ptype_class \
-       "ptype class A" "" "class" "A" \
+       "class A" "" "class" "A" \
        {
            { field public "int a;" }
            { field public "int x;" }
@@ -155,7 +153,7 @@ proc test_ptype_class_objects {} {
     # Derived class.
 
     cp_test_ptype_class \
-       "ptype class B" "" "class" "B" \
+       "class B" "" "class" "B" \
        {
            { base         "public A" }
            { field public "int b;" }
@@ -165,7 +163,7 @@ proc test_ptype_class_objects {} {
     # Derived class.
 
     cp_test_ptype_class \
-       "ptype class C" "" "class" "C" \
+       "class C" "" "class" "C" \
        {
            { base         "public A" }
            { field public "int c;" }
@@ -175,7 +173,7 @@ proc test_ptype_class_objects {} {
     # Derived class, multiple inheritance.
 
     cp_test_ptype_class \
-       "ptype class D" "" "class" "D" \
+       "class D" "" "class" "D" \
        {
            { base         "public B" }
            { base         "public C" }
@@ -186,7 +184,7 @@ proc test_ptype_class_objects {} {
     # Derived class.
 
     cp_test_ptype_class \
-       "ptype class E" "" "class" "E" \
+       "class E" "" "class" "E" \
        {
            { base         "public D" }
            { field public "int e;" }
@@ -199,7 +197,7 @@ proc test_ptype_class_objects {} {
     # static methods whose name is the same as their argument mangling.
  
     cp_test_ptype_class \
-       "ptype class Static" "" "class" "Static" \
+       "class Static" "" "class" "Static" \
        {
            { method public "static void ii(int, int);" }
        }
@@ -209,7 +207,7 @@ proc test_ptype_class_objects {} {
     # A virtual base class.
 
     cp_test_ptype_class \
-       "ptype class vA" "" "class" "vA" \
+       "class vA" "" "class" "vA" \
        {
            { field public "int va;" }
            { field public "int vx;" }
@@ -218,7 +216,7 @@ proc test_ptype_class_objects {} {
     # A derived class with a virtual base.
 
     cp_test_ptype_class \
-       "ptype class vB" "" "class" "vB" \
+       "class vB" "" "class" "vB" \
        {
            { base         "public virtual vA" }
            { vbase        "vA" }
@@ -229,7 +227,7 @@ proc test_ptype_class_objects {} {
     # Another derived class with a virtual base.
 
     cp_test_ptype_class \
-       "ptype class vC" "" "class" "vC" \
+       "class vC" "" "class" "vC" \
        {
            { base         "public virtual vA" }
            { vbase        "vA" }
@@ -240,7 +238,7 @@ proc test_ptype_class_objects {} {
     # A classic diamond class.
 
     cp_test_ptype_class \
-       "ptype class vD" "" "class" "vD" \
+       "class vD" "" "class" "vD" \
        {
            { base         "public virtual vB" }
            { base         "public virtual vC" }
@@ -253,7 +251,7 @@ proc test_ptype_class_objects {} {
     # A class derived from a diamond class.
 
     cp_test_ptype_class \
-       "ptype class vE" "" "class" "vE" \
+       "class vE" "" "class" "vE" \
        {
            { base         "public virtual vD" }
            { vbase        "vD" }
@@ -266,7 +264,7 @@ proc test_ptype_class_objects {} {
     # A base class.
 
     cp_test_ptype_class \
-       "ptype class Base1" "" "class" "Base1" \
+       "class Base1" "" "class" "Base1" \
        {
            { field  public "int x;" }
            { method public "Base1(int);" }
@@ -275,7 +273,7 @@ proc test_ptype_class_objects {} {
     # Another base class.
 
     cp_test_ptype_class \
-       "ptype class Foo" "" "class" "Foo" \
+       "class Foo" "" "class" "Foo" \
        {
            { field public "int x;" }
            { field public "int y;" }
@@ -302,7 +300,7 @@ proc test_ptype_class_objects {} {
     # A multiple inheritance derived class.
 
     cp_test_ptype_class \
-       "ptype class Bar" "" "class" "Bar" \
+       "class Bar" "" "class" "Bar" \
        {
            { base          "public Base1" }
            { base          "public Foo" }
@@ -310,6 +308,73 @@ proc test_ptype_class_objects {} {
            { method public "Bar(int, int, int);" }
        }
 
+    # Derived class with typedef'd baseclass with virtual methods.
+
+    cp_test_ptype_class \
+       "class DynamicBar" "" "class" "DynamicBar" \
+       {
+           { base          "public DynamicBase2" }
+           { field  public "int y;" }
+           { method public "DynamicBar(int, int);" }
+       }
+
+    # Classes with typedefs of different access.
+
+    cp_test_ptype_class \
+       "class class_with_typedefs" "" "class" "class_with_typedefs" \
+       {
+           { field protected \
+                 "class_with_typedefs::public_int public_int_;" }
+           { field protected \
+                 "class_with_typedefs::protected_int protected_int_;" }
+           { field protected \
+                 "class_with_typedefs::private_int private_int_;" }
+           { method public "class_with_typedefs(void);" }
+           { method public "class_with_typedefs::public_int add_public(class_with_typedefs::public_int);" }
+           { method public \
+                 "class_with_typedefs::public_int add_all(int);" }
+           { method protected "class_with_typedefs::protected_int add_protected(class_with_typedefs::protected_int);" }
+           { method private "class_with_typedefs::private_int add_private(class_with_typedefs::private_int);" }
+           { typedef public "typedef int public_int;" }
+           { typedef protected "typedef int protected_int;" }
+           { typedef private "typedef int private_int;" }
+       }
+
+    cp_test_ptype_class \
+       "class class_with_public_typedef" "" "class" \
+       "class_with_public_typedef" {
+           { field private "int a;" }
+           { field public "class_with_public_typedef::INT b;" }
+           { typedef public "typedef int INT;" }
+       }
+    cp_test_ptype_class \
+       "class class_with_protected_typedef" "" "class" \
+       "class_with_protected_typedef" {
+           { field private "int a;" }
+           { field protected "class_with_protected_typedef::INT b;" }
+           { typedef protected "typedef int INT;" }
+       }
+    cp_test_ptype_class \
+       "struct struct_with_protected_typedef" "" "struct" \
+       "struct_with_protected_typedef" {
+           { field public "int a;" }
+           { field protected "struct_with_protected_typedef::INT b;" }
+           { typedef protected "typedef int INT;" }
+       }
+    cp_test_ptype_class \
+       "struct struct_with_private_typedef" "" "struct" \
+       "struct_with_private_typedef" {
+           { field public "int a;" }
+           { field private "struct_with_private_typedef::INT b;" }
+           { typedef private "typedef int INT;" }
+       }
+
+    # For the following two cases, we cannot use cp_test_ptype_class.
+    # We need to explicitly check whether the access label was suppressed.
+    set ws {[ \t\r\n]*}
+    foreach {tag lbl} {"class" "private" "struct" "public"} {
+       gdb_test "ptype/r ${tag}_with_${lbl}_typedef" "type = $tag ${tag}_with_${lbl}_typedef \{${ws}int a;${ws}${tag}_with_${lbl}_typedef::INT b;${ws}typedef int INT;${ws}\}"
+    }
 }
 
 # Test simple access to class members.
@@ -413,7 +478,7 @@ proc test_enums {} {
     # ptype on the enum member
 
     gdb_test_multiple "ptype obj_with_enum.priv_enum" "ptype obj_with_enum.priv_enum" {
-        -re "type = enum ClassWithEnum::PrivEnum \{ ?(ClassWithEnum::)?red, (ClassWithEnum::)?green, (ClassWithEnum::)?blue, (ClassWithEnum::)?yellow = 42 ?\}$nl$gdb_prompt $" {
+        -re "type = enum ClassWithEnum::PrivEnum (: unsigned (int|short|char) )?\{ ?(ClassWithEnum::)?red, (ClassWithEnum::)?green, (ClassWithEnum::)?blue, (ClassWithEnum::)?yellow = 42 ?\}$nl$gdb_prompt $" {
            pass "ptype obj_with_enum.priv_enum"
         }
        -re "type = enum PrivEnum \{ ?(ClassWithEnum::)?red, (ClassWithEnum::)?green, (ClassWithEnum::)?blue, (ClassWithEnum::)?yellow = 42 ?\}$nl$gdb_prompt $" {
@@ -448,7 +513,7 @@ proc test_enums {} {
     # stabs, we probably can't get this right; under DWARF-2, we can.
 
     cp_test_ptype_class \
-       "ptype obj_with_enum" "" "class" "ClassWithEnum" \
+       "obj_with_enum" "" "class" "ClassWithEnum" \
        {
            { field public "ClassWithEnum::PrivEnum priv_enum;" }
            { field public "int x;" }
@@ -519,8 +584,8 @@ proc test_static_members {} {
     gdb_test "print Foo::st" "\\$\[0-9\]+ = 100"
     gdb_test_no_output "set foo.st = 200" ""
     gdb_test "print bar.st" "\\$\[0-9\]+ = 200"
-    gdb_test "print &foo.st" "\\$\[0-9\]+ = \\(int ?\\*\\) $hex"
-    gdb_test "print &Bar::st" "\\$\[0-9\]+ = \\(int ?\\*\\) $hex"
+    gdb_test "print &foo.st" "\\$\[0-9\]+ = \\(int ?\\*\\) $hex <Foo::st>"
+    gdb_test "print &Bar::st" "\\$\[0-9\]+ = \\(int ?\\*\\) $hex <Foo::st>"
     gdb_test "print *\$" "\\$\[0-9\]+ = 200"
 
     gdb_test_no_output "set print static-members off"
@@ -538,24 +603,18 @@ proc test_static_members {} {
     gdb_test "print cnsi" \
        "{x = 30, y = 40, static null = {x = 0, y = 0, static null = <same as static member of an already seen type>, static yy = {z = 5, static xx = {x = 1, y = 2, static null = <same as static member of an already seen type>, static yy = <same as static member of an already seen type>}}}, static yy = <same as static member of an already seen type>}" \
        "print cnsi with static members"
+
+    # Another case of infinite recursion.
+    gdb_test "print Outer::instance" \
+       "{inner = {static instance = {static instance = <same as static member of an already seen type>}}, static instance = {inner = {static instance = {static instance = <same as static member of an already seen type>}}, static instance = <same as static member of an already seen type>}}" \
+       "print recursive static member"
 }
 
 proc do_tests {} {
-    global subdir
-    global objdir
-    global srcdir
-    global binfile
     global gdb_prompt
     global nl
 
 
-    # Start with a fresh gdb.
-
-    gdb_exit
-    gdb_start
-    gdb_reinitialize_dir $srcdir/$subdir
-    gdb_load $binfile
-
     gdb_test_no_output "set language c++" ""
     gdb_test_no_output "set width 0" ""
 
This page took 0.047736 seconds and 4 git commands to generate.