Jan Kratochvil 2d024d1
Index: gdb-7.6.1/gdb/c-exp.y
Jan Kratochvil 2d024d1
===================================================================
Jan Kratochvil 2d024d1
--- gdb-7.6.1.orig/gdb/c-exp.y	2013-11-09 17:29:19.336729300 +0100
Jan Kratochvil 2d024d1
+++ gdb-7.6.1/gdb/c-exp.y	2013-11-09 17:29:21.935727454 +0100
Jan Kratochvil 2d024d1
@@ -2890,6 +2890,30 @@ classify_inner_name (const struct block
Jan Kratochvil 2d024d1
     {
Jan Kratochvil 2d024d1
     case LOC_BLOCK:
Jan Kratochvil 2d024d1
     case LOC_LABEL:
Jan Kratochvil 2d024d1
+      {
Jan Kratochvil 2d024d1
+	struct field_of_this_result fot;
Jan Kratochvil 2d024d1
+
Jan Kratochvil 2d024d1
+	/* We might have erroneously found a constructor where we wanted
Jan Kratochvil 2d024d1
+	   a type name.  The trick is ascertaining what the user wanted.
Jan Kratochvil 2d024d1
+	   If cp_lookup_nested_symbol found a constructor, but it is for a
Jan Kratochvil 2d024d1
+	   different type than CONTEXT, then this is really a type, not a
Jan Kratochvil 2d024d1
+	   constructor.  Look for the type and return that.  */
Jan Kratochvil 2d024d1
+	memset (&fot, 0, sizeof (fot));
Jan Kratochvil 2d024d1
+	check_field (type, copy, &fot;;
Jan Kratochvil 2d024d1
+	if (fot.fn_field != NULL
Jan Kratochvil 2d024d1
+	    && TYPE_FN_FIELD_CONSTRUCTOR (fot.fn_field->fn_fields, 0)
Jan Kratochvil 2d024d1
+	    && !types_equal (type, fot.type))
Jan Kratochvil 2d024d1
+	  {
Jan Kratochvil 2d024d1
+	    struct symbol *sym;
Jan Kratochvil 2d024d1
+
Jan Kratochvil 2d024d1
+	    sym = lookup_symbol (copy, block, STRUCT_DOMAIN, NULL);
Jan Kratochvil 2d024d1
+	    if (sym != NULL)
Jan Kratochvil 2d024d1
+	      {
Jan Kratochvil 2d024d1
+		yylval.tsym.type = SYMBOL_TYPE (sym);
Jan Kratochvil 2d024d1
+		return TYPENAME;
Jan Kratochvil 2d024d1
+	      }
Jan Kratochvil 2d024d1
+	  }
Jan Kratochvil 2d024d1
+      }
Jan Kratochvil 2d024d1
       return ERROR;
Jan Kratochvil 2d024d1
 
Jan Kratochvil 2d024d1
     case LOC_TYPEDEF:
Jan Kratochvil 2d024d1
Index: gdb-7.6.1/gdb/symtab.c
Jan Kratochvil 2d024d1
===================================================================
Jan Kratochvil 2d024d1
--- gdb-7.6.1.orig/gdb/symtab.c	2013-11-09 17:29:19.338729298 +0100
Jan Kratochvil 2d024d1
+++ gdb-7.6.1/gdb/symtab.c	2013-11-09 17:29:21.936727453 +0100
Jan Kratochvil 2d024d1
@@ -1260,7 +1260,7 @@ lookup_language_this (const struct langu
Jan Kratochvil 2d024d1
    return 1 if the component named NAME from the ultimate target
Jan Kratochvil 2d024d1
    structure/union is defined, otherwise, return 0.  */
Jan Kratochvil 2d024d1
 
Jan Kratochvil 2d024d1
-static int
Jan Kratochvil 2d024d1
+int
Jan Kratochvil 2d024d1
 check_field (struct type *type, const char *name,
Jan Kratochvil 2d024d1
 	     struct field_of_this_result *is_a_field_of_this)
Jan Kratochvil 2d024d1
 {
Jan Kratochvil 2d024d1
Index: gdb-7.6.1/gdb/symtab.h
Jan Kratochvil 2d024d1
===================================================================
Jan Kratochvil 2d024d1
--- gdb-7.6.1.orig/gdb/symtab.h	2013-11-09 17:29:19.339729298 +0100
Jan Kratochvil 2d024d1
+++ gdb-7.6.1/gdb/symtab.h	2013-11-09 17:27:11.329820268 +0100
Jan Kratochvil 2d024d1
@@ -1318,4 +1318,9 @@ void iterate_over_symbols (const struct
Jan Kratochvil 2d024d1
 struct cleanup *demangle_for_lookup (const char *name, enum language lang,
Jan Kratochvil 2d024d1
 				     const char **result_name);
Jan Kratochvil 2d024d1
 
Jan Kratochvil 2d024d1
+/* See comment in symtab.c.  */
Jan Kratochvil 2d024d1
+
Jan Kratochvil 2d024d1
+int check_field (struct type *type, const char *name,
Jan Kratochvil 2d024d1
+		 struct field_of_this_result *is_a_field_of_this);
Jan Kratochvil 2d024d1
+
Jan Kratochvil 2d024d1
 #endif /* !defined(SYMTAB_H) */
Jan Kratochvil 2d024d1
Index: gdb-7.6.1/gdb/valops.c
Jan Kratochvil 2d024d1
===================================================================
Jan Kratochvil 2d024d1
--- gdb-7.6.1.orig/gdb/valops.c	2013-11-09 17:29:19.340729297 +0100
Jan Kratochvil 2d024d1
+++ gdb-7.6.1/gdb/valops.c	2013-11-09 17:28:02.417784136 +0100
Jan Kratochvil 2d024d1
@@ -3401,10 +3401,35 @@ value_struct_elt_for_reference (struct t
Jan Kratochvil 2d024d1
 	    return value_from_longest
Jan Kratochvil 2d024d1
 	      (lookup_memberptr_type (TYPE_FIELD_TYPE (t, i), domain),
Jan Kratochvil 2d024d1
 	       offset + (TYPE_FIELD_BITPOS (t, i) >> 3));
Jan Kratochvil 2d024d1
-	  else if (noside == EVAL_AVOID_SIDE_EFFECTS)
Jan Kratochvil 2d024d1
+	  else if (noside != EVAL_NORMAL)
Jan Kratochvil 2d024d1
 	    return allocate_value (TYPE_FIELD_TYPE (t, i));
Jan Kratochvil 2d024d1
 	  else
Jan Kratochvil 2d024d1
-	    error (_("Cannot reference non-static field \"%s\""), name);
Jan Kratochvil 2d024d1
+	    {
Jan Kratochvil 2d024d1
+	      /* Try to evaluate NAME as a qualified name with implicit
Jan Kratochvil 2d024d1
+		 this pointer.  In this case, attempt to return the
Jan Kratochvil 2d024d1
+		 equivalent to `this->*(&TYPE::NAME)'.  */
Jan Kratochvil 2d024d1
+	      v = value_of_this_silent (current_language);
Jan Kratochvil 2d024d1
+	      if (v != NULL)
Jan Kratochvil 2d024d1
+		{
Jan Kratochvil 2d024d1
+		  struct value *ptr;
Jan Kratochvil 2d024d1
+		  long mem_offset;
Jan Kratochvil 2d024d1
+		  struct type *type, *tmp;
Jan Kratochvil 2d024d1
+
Jan Kratochvil 2d024d1
+		  ptr = value_aggregate_elt (domain, name, NULL, 1, noside);
Jan Kratochvil 2d024d1
+		  type = check_typedef (value_type (ptr));
Jan Kratochvil 2d024d1
+		  gdb_assert (type != NULL
Jan Kratochvil 2d024d1
+			      && TYPE_CODE (type) == TYPE_CODE_MEMBERPTR);
Jan Kratochvil 2d024d1
+		  tmp = lookup_pointer_type (TYPE_DOMAIN_TYPE (type));
Jan Kratochvil 2d024d1
+		  v = value_cast_pointers (tmp, v, 1);
Jan Kratochvil 2d024d1
+		  mem_offset = value_as_long (ptr);
Jan Kratochvil 2d024d1
+		  tmp = lookup_pointer_type (TYPE_TARGET_TYPE (type));
Jan Kratochvil 2d024d1
+		  result = value_from_pointer (tmp,
Jan Kratochvil 2d024d1
+					       value_as_long (v) + mem_offset);
Jan Kratochvil 2d024d1
+		  return value_ind (result);
Jan Kratochvil 2d024d1
+		}
Jan Kratochvil 2d024d1
+
Jan Kratochvil 2d024d1
+	      error (_("Cannot reference non-static field \"%s\""), name);
Jan Kratochvil 2d024d1
+	    }
Jan Kratochvil 2d024d1
 	}
Jan Kratochvil 2d024d1
     }
Jan Kratochvil 2d024d1
 
Jan Kratochvil 2d024d1
Index: gdb-7.6.1/gdb/testsuite/gdb.cp/impl-this.cc
Jan Kratochvil 2d024d1
===================================================================
Jan Kratochvil 2d024d1
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
Jan Kratochvil 2d024d1
+++ gdb-7.6.1/gdb/testsuite/gdb.cp/impl-this.cc	2013-11-09 17:29:21.938727452 +0100
Jan Kratochvil 2d024d1
@@ -0,0 +1,96 @@
Jan Kratochvil 2d024d1
+/* This testcase is part of GDB, the GNU debugger.
Jan Kratochvil 2d024d1
+
Jan Kratochvil 2d024d1
+   Copyright 2013 Free Software Foundation, Inc.
Jan Kratochvil 2d024d1
+
Jan Kratochvil 2d024d1
+   This program is free software; you can redistribute it and/or modify
Jan Kratochvil 2d024d1
+   it under the terms of the GNU General Public License as published by
Jan Kratochvil 2d024d1
+   the Free Software Foundation; either version 3 of the License, or
Jan Kratochvil 2d024d1
+   (at your option) any later version.
Jan Kratochvil 2d024d1
+
Jan Kratochvil 2d024d1
+   This program is distributed in the hope that it will be useful,
Jan Kratochvil 2d024d1
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
Jan Kratochvil 2d024d1
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
Jan Kratochvil 2d024d1
+   GNU General Public License for more details.
Jan Kratochvil 2d024d1
+
Jan Kratochvil 2d024d1
+   You should have received a copy of the GNU General Public License
Jan Kratochvil 2d024d1
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
Jan Kratochvil 2d024d1
+
Jan Kratochvil 2d024d1
+#ifdef DEBUG
Jan Kratochvil 2d024d1
+#include <stdio.h>
Jan Kratochvil 2d024d1
+#endif
Jan Kratochvil 2d024d1
+
Jan Kratochvil 2d024d1
+class A
Jan Kratochvil 2d024d1
+{
Jan Kratochvil 2d024d1
+public:
Jan Kratochvil 2d024d1
+  int i;
Jan Kratochvil 2d024d1
+  int z;
Jan Kratochvil 2d024d1
+  A () : i (1), z (10) {}
Jan Kratochvil 2d024d1
+};
Jan Kratochvil 2d024d1
+
Jan Kratochvil 2d024d1
+class B : public virtual A
Jan Kratochvil 2d024d1
+{
Jan Kratochvil 2d024d1
+public:
Jan Kratochvil 2d024d1
+  int i;
Jan Kratochvil 2d024d1
+  B () : i (2) {}
Jan Kratochvil 2d024d1
+};
Jan Kratochvil 2d024d1
+
Jan Kratochvil 2d024d1
+class C : public virtual A
Jan Kratochvil 2d024d1
+{
Jan Kratochvil 2d024d1
+public:
Jan Kratochvil 2d024d1
+  int i;
Jan Kratochvil 2d024d1
+  int c;
Jan Kratochvil 2d024d1
+  C () : i (3), c (30) {}
Jan Kratochvil 2d024d1
+};
Jan Kratochvil 2d024d1
+
Jan Kratochvil 2d024d1
+class D : public B, public C
Jan Kratochvil 2d024d1
+{
Jan Kratochvil 2d024d1
+public:
Jan Kratochvil 2d024d1
+  int i;
Jan Kratochvil 2d024d1
+  int x;
Jan Kratochvil 2d024d1
+  D () : i (4), x (40) {}
Jan Kratochvil 2d024d1
+
Jan Kratochvil 2d024d1
+#ifdef DEBUG
Jan Kratochvil 2d024d1
+#define SUM(X)					\
Jan Kratochvil 2d024d1
+  do						\
Jan Kratochvil 2d024d1
+    {						\
Jan Kratochvil 2d024d1
+      sum += (X);				\
Jan Kratochvil 2d024d1
+      printf ("" #X " = %d\n", (X));		\
Jan Kratochvil 2d024d1
+    }						\
Jan Kratochvil 2d024d1
+  while (0)
Jan Kratochvil 2d024d1
+#else
Jan Kratochvil 2d024d1
+#define SUM(X) sum += (X)
Jan Kratochvil 2d024d1
+#endif
Jan Kratochvil 2d024d1
+
Jan Kratochvil 2d024d1
+int
Jan Kratochvil 2d024d1
+f (void)
Jan Kratochvil 2d024d1
+  {
Jan Kratochvil 2d024d1
+    int sum = 0;
Jan Kratochvil 2d024d1
+
Jan Kratochvil 2d024d1
+    SUM (i);
Jan Kratochvil 2d024d1
+    SUM (D::i);
Jan Kratochvil 2d024d1
+    SUM (D::B::i);
Jan Kratochvil 2d024d1
+    SUM (B::i);
Jan Kratochvil 2d024d1
+    SUM (D::C::i);
Jan Kratochvil 2d024d1
+    SUM (C::i);
Jan Kratochvil 2d024d1
+    SUM (D::B::A::i);
Jan Kratochvil 2d024d1
+    SUM (B::A::i);
Jan Kratochvil 2d024d1
+    SUM (A::i);
Jan Kratochvil 2d024d1
+    SUM (D::C::A::i);
Jan Kratochvil 2d024d1
+    SUM (C::A::i);
Jan Kratochvil 2d024d1
+    SUM (D::x);
Jan Kratochvil 2d024d1
+    SUM (x);
Jan Kratochvil 2d024d1
+    SUM (D::C::c);
Jan Kratochvil 2d024d1
+    SUM (C::c);
Jan Kratochvil 2d024d1
+    SUM (c);
Jan Kratochvil 2d024d1
+
Jan Kratochvil 2d024d1
+    return sum;
Jan Kratochvil 2d024d1
+  }
Jan Kratochvil 2d024d1
+};
Jan Kratochvil 2d024d1
+
Jan Kratochvil 2d024d1
+int
Jan Kratochvil 2d024d1
+main (void)
Jan Kratochvil 2d024d1
+{
Jan Kratochvil 2d024d1
+  D d;
Jan Kratochvil 2d024d1
+
Jan Kratochvil 2d024d1
+  return d.f ();
Jan Kratochvil 2d024d1
+}
Jan Kratochvil 2d024d1
Index: gdb-7.6.1/gdb/testsuite/gdb.cp/impl-this.exp
Jan Kratochvil 2d024d1
===================================================================
Jan Kratochvil 2d024d1
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
Jan Kratochvil 2d024d1
+++ gdb-7.6.1/gdb/testsuite/gdb.cp/impl-this.exp	2013-11-09 17:29:21.939727451 +0100
Jan Kratochvil 2d024d1
@@ -0,0 +1,89 @@
Jan Kratochvil 2d024d1
+# Copyright 2013 Free Software Foundation, Inc.
Jan Kratochvil 2d024d1
+
Jan Kratochvil 2d024d1
+# This program is free software; you can redistribute it and/or modify
Jan Kratochvil 2d024d1
+# it under the terms of the GNU General Public License as published by
Jan Kratochvil 2d024d1
+# the Free Software Foundation; either version 3 of the License, or
Jan Kratochvil 2d024d1
+# (at your option) any later version.
Jan Kratochvil 2d024d1
+#
Jan Kratochvil 2d024d1
+# This program is distributed in the hope that it will be useful,
Jan Kratochvil 2d024d1
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
Jan Kratochvil 2d024d1
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
Jan Kratochvil 2d024d1
+# GNU General Public License for more details.
Jan Kratochvil 2d024d1
+#
Jan Kratochvil 2d024d1
+# You should have received a copy of the GNU General Public License
Jan Kratochvil 2d024d1
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
Jan Kratochvil 2d024d1
+
Jan Kratochvil 2d024d1
+# This file is part of the gdb testsuite
Jan Kratochvil 2d024d1
+
Jan Kratochvil 2d024d1
+# Test expressions which assume an implicit "this" with a qualified
Jan Kratochvil 2d024d1
+# name.
Jan Kratochvil 2d024d1
+
Jan Kratochvil 2d024d1
+if {[skip_cplus_tests]} { continue }
Jan Kratochvil 2d024d1
+
Jan Kratochvil 2d024d1
+standard_testfile .cc
Jan Kratochvil 2d024d1
+
Jan Kratochvil 2d024d1
+if {[prepare_for_testing $testfile.exp $testfile $srcfile {debug c++}]} {
Jan Kratochvil 2d024d1
+    return -1
Jan Kratochvil 2d024d1
+}
Jan Kratochvil 2d024d1
+
Jan Kratochvil 2d024d1
+# First test expressions when there is no context.
Jan Kratochvil 2d024d1
+gdb_test "print i" "No symbol \"i\" in current context."
Jan Kratochvil 2d024d1
+gdb_test "print D::i" "Cannot reference non-static field \"i\""
Jan Kratochvil 2d024d1
+gdb_test "print D::B::i" "Cannot reference non-static field \"i\""
Jan Kratochvil 2d024d1
+gdb_test "print B::i" "Cannot reference non-static field \"i\""
Jan Kratochvil 2d024d1
+gdb_test "print D::C::i" "Cannot reference non-static field \"i\""
Jan Kratochvil 2d024d1
+gdb_test "print C::i" "Cannot reference non-static field \"i\""
Jan Kratochvil 2d024d1
+gdb_test "print D::B::A::i" "Cannot reference non-static field \"i\""
Jan Kratochvil 2d024d1
+gdb_test "print B::A::i" "Cannot reference non-static field \"i\""
Jan Kratochvil 2d024d1
+gdb_test "print A::i" "Cannot reference non-static field \"i\""
Jan Kratochvil 2d024d1
+gdb_test "print D::C::A::i" "Cannot reference non-static field \"i\""
Jan Kratochvil 2d024d1
+gdb_test "print C::A::i" "Cannot reference non-static field \"i\""
Jan Kratochvil 2d024d1
+gdb_test "print D::x" "Cannot reference non-static field \"x\""
Jan Kratochvil 2d024d1
+gdb_test "print x" "No symbol \"x\" in current context."
Jan Kratochvil 2d024d1
+gdb_test "print D::C::c" "Cannot reference non-static field \"c\""
Jan Kratochvil 2d024d1
+gdb_test "print C::c" "Cannot reference non-static field \"c\""
Jan Kratochvil 2d024d1
+gdb_test "print c" "No symbol \"c\" in current context."
Jan Kratochvil 2d024d1
+
Jan Kratochvil 2d024d1
+# Run to D::f.
Jan Kratochvil 2d024d1
+if {![runto_main]} {
Jan Kratochvil 2d024d1
+    perror "couldn't run to main"
Jan Kratochvil 2d024d1
+    continue
Jan Kratochvil 2d024d1
+}
Jan Kratochvil 2d024d1
+
Jan Kratochvil 2d024d1
+gdb_breakpoint "D::f"
Jan Kratochvil 2d024d1
+gdb_continue_to_breakpoint "run to D::f"
Jan Kratochvil 2d024d1
+
Jan Kratochvil 2d024d1
+# Now test valid expressions in the class hierarchy for D.
Jan Kratochvil 2d024d1
+gdb_test "print i" "= 4"
Jan Kratochvil 2d024d1
+gdb_test "print D::i" "= 4"
Jan Kratochvil 2d024d1
+gdb_test "print D::B::i" "= 2"
Jan Kratochvil 2d024d1
+gdb_test "print B::i" "= 2"
Jan Kratochvil 2d024d1
+gdb_test "print D::C::i" "= 3"
Jan Kratochvil 2d024d1
+gdb_test "print C::i" "= 3"
Jan Kratochvil 2d024d1
+gdb_test "print D::B::A::i" "= 1"
Jan Kratochvil 2d024d1
+gdb_test "print B::A::i" "= 1"
Jan Kratochvil 2d024d1
+gdb_test "print A::i" "= 1"
Jan Kratochvil 2d024d1
+gdb_test "print D::C::A::i" "= 1"
Jan Kratochvil 2d024d1
+gdb_test "print C::A::i" "= 1"
Jan Kratochvil 2d024d1
+gdb_test "print D::x" "= 40"
Jan Kratochvil 2d024d1
+gdb_test "print x" "= 40"
Jan Kratochvil 2d024d1
+gdb_test "print D::C::c" "= 30"
Jan Kratochvil 2d024d1
+gdb_test "print C::c" "= 30"
Jan Kratochvil 2d024d1
+gdb_test "print c" "= 30"
Jan Kratochvil 2d024d1
+
Jan Kratochvil 2d024d1
+# Test some invalid expressions
Jan Kratochvil 2d024d1
+gdb_test "print D::B::c" "There is no field named c"
Jan Kratochvil 2d024d1
+gdb_test "print D::B::A::c" "There is no field named c"
Jan Kratochvil 2d024d1
+gdb_test "print D::C::A::c" "There is no field named c"
Jan Kratochvil 2d024d1
+gdb_test "print B::c" "There is no field named c"
Jan Kratochvil 2d024d1
+gdb_test "print B::A::c" "There is no field named c"
Jan Kratochvil 2d024d1
+gdb_test "print C::A::c" "There is no field named c"
Jan Kratochvil 2d024d1
+gdb_test "print D::B::x" "There is no field named x"
Jan Kratochvil 2d024d1
+gdb_test "print D::B::A::x" "There is no field named x"
Jan Kratochvil 2d024d1
+gdb_test "print B::x" "There is no field named x"
Jan Kratochvil 2d024d1
+gdb_test "print B::A::x" "There is no field named x"
Jan Kratochvil 2d024d1
+gdb_test "print D::C::x" "There is no field named x"
Jan Kratochvil 2d024d1
+gdb_test "print C::x" "There is no field named x"
Jan Kratochvil 2d024d1
+gdb_test "print D::C::A::x" "There is no field named x"
Jan Kratochvil 2d024d1
+gdb_test "print C::A::x" "There is no field named x"
Jan Kratochvil 2d024d1
+