Bug 11846 - struct should not permit ->
Summary: struct should not permit ->
Status: RESOLVED INVALID
Alias: None
Product: gdb
Classification: Unclassified
Component: symtab (show other bugs)
Version: unknown
: P2 enhancement
Target Milestone: 7.1
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-07-28 11:03 UTC by Jan Kratochvil
Modified: 2010-07-28 16:33 UTC (History)
1 user (show)

See Also:
Host:
Target: x86_64-unknown-linux-gnu
Build:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jan Kratochvil 2010-07-28 11:03:50 UTC
struct
  {
    int x;
  }
s = { 42 };
int main (void) { return s.x; }

OK:
(gdb) p s.x
$2 = 42
But this is wrong:
(gdb) p s->x
$3 = 42
GCC prints:
.c:6: error: invalid type argument of ‘->’ (have ‘struct <anonymous>’)

GNU gdb (GDB) 7.2.50.20100728-cvs
Comment 1 Andreas Schwab 2010-07-28 11:17:54 UTC
GDB also permits . on a pointer to struct, so this could be considered
convenience.  Apparently . and -> are basically treated the same.
Comment 2 Pedro Alves 2010-07-28 11:24:22 UTC
From the manual:

@item .@r{, }->
Structure member, and pointer-to-structure member.  For convenience,
@value{GDBN} regards the two as equivalent, choosing whether to dereference a
pointer based on the stored type information.
Defined on @code{struct} and @code{union} data.
Comment 3 Jan Kratochvil 2010-07-28 11:28:14 UTC
I did not know, OK, thanks.

It is true GDB also intentionally lookups `static' objects from other files
which is also not exactly following the C language rules.

Which I may disagree with but this is all I can do.
Comment 4 Tom Tromey 2010-07-28 16:33:33 UTC
FWIW --

I think there are some minor differences between the two.
And, we may introduce a few more, since it isn't clear that, e.g.,
"foo.x" should use an overloaded operator->