public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/46206] New: using typedef-name error with typedef name hiding struct name
@ 2010-10-28  1:58 nathan.keynes at oracle dot com
  2010-10-28  2:16 ` [Bug c++/46206] " paolo.carlini at oracle dot com
                   ` (11 more replies)
  0 siblings, 12 replies; 13+ messages in thread
From: nathan.keynes at oracle dot com @ 2010-10-28  1:58 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=46206

           Summary: using typedef-name error with typedef name hiding
                    struct name
           Product: gcc
           Version: 4.1.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: nathan.keynes@oracle.com


G++ rejects the following code:

class Foo
{
    bool a, b, c, d;
    typedef struct Bar { } Bar;
    virtual void foo(void) {
        struct Bar bar;
    }
};

example.cc: In member function ‘virtual void Foo::foo()’:
example.cc:6: error: using typedef-name ‘Foo::Bar’ after ‘struct’
example.cc:4: error: ‘Foo::Bar’ has a previous declaration here
example.cc:6: error: invalid type in declaration before ‘;’ token

but accepts many similar examples, including:
class Foo
{
    bool a, b, c;
    typedef struct Bar { } Bar;
    virtual void foo(void) {
        struct Bar bar;
    }
};

This behaviour is reproducible on x86_64-redhat-linux (4.1.2 and 4.4.0) and
i386-pc-solaris2.11 (4.2.4, 4.3.4 and 4.5.1)

I'm uncertain if this is strictly legal or not per the standard, but it doesn't
seem to make sense to accept one of these cases but not the other.


^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug c++/46206] using typedef-name error with typedef name hiding struct name
  2010-10-28  1:58 [Bug c++/46206] New: using typedef-name error with typedef name hiding struct name nathan.keynes at oracle dot com
@ 2010-10-28  2:16 ` paolo.carlini at oracle dot com
  2013-08-05 10:59 ` paolo.carlini at oracle dot com
                   ` (10 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: paolo.carlini at oracle dot com @ 2010-10-28  2:16 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=46206

Paolo Carlini <paolo.carlini at oracle dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2010.10.28 02:16:05
     Ever Confirmed|0                           |1

--- Comment #1 from Paolo Carlini <paolo.carlini at oracle dot com> 2010-10-28 02:16:05 UTC ---
Crazy.


^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug c++/46206] using typedef-name error with typedef name hiding struct name
  2010-10-28  1:58 [Bug c++/46206] New: using typedef-name error with typedef name hiding struct name nathan.keynes at oracle dot com
  2010-10-28  2:16 ` [Bug c++/46206] " paolo.carlini at oracle dot com
@ 2013-08-05 10:59 ` paolo.carlini at oracle dot com
  2013-08-05 13:47 ` paolo.carlini at oracle dot com
                   ` (9 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: paolo.carlini at oracle dot com @ 2013-08-05 10:59 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=46206

--- Comment #2 from Paolo Carlini <paolo.carlini at oracle dot com> ---
The difference is that in the first case the TYPE_DECL Bar is regenerated and
the DECL_IMPLICIT_TYPEDEF_P bit is lost, the true value set earlier by
create_implicit_typedef is lost.


^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug c++/46206] using typedef-name error with typedef name hiding struct name
  2010-10-28  1:58 [Bug c++/46206] New: using typedef-name error with typedef name hiding struct name nathan.keynes at oracle dot com
  2010-10-28  2:16 ` [Bug c++/46206] " paolo.carlini at oracle dot com
  2013-08-05 10:59 ` paolo.carlini at oracle dot com
@ 2013-08-05 13:47 ` paolo.carlini at oracle dot com
  2013-08-05 19:00 ` paolo.carlini at oracle dot com
                   ` (8 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: paolo.carlini at oracle dot com @ 2013-08-05 13:47 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=46206

--- Comment #3 from Paolo Carlini <paolo.carlini at oracle dot com> ---
More correctly: it seems that when we parse "typedef struct Bar { } Bar;" we
create two TYPE_DECL: first, one marked as DECL_IMPLICIT_TYPEDEF_P in pushtag_1
(via create_implicit_typedef); then a second, real, one in grokdeclarator, via
build_lang_decl (TYPE_DECL... ). When we do lookup for "struct Bar bar", it can
happen, depending on layout details, that the *second* one is found, thus the
check in check_elaborated_type_specifier triggers.


^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug c++/46206] using typedef-name error with typedef name hiding struct name
  2010-10-28  1:58 [Bug c++/46206] New: using typedef-name error with typedef name hiding struct name nathan.keynes at oracle dot com
                   ` (2 preceding siblings ...)
  2013-08-05 13:47 ` paolo.carlini at oracle dot com
@ 2013-08-05 19:00 ` paolo.carlini at oracle dot com
  2013-08-07 10:11 ` paolo.carlini at oracle dot com
                   ` (7 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: paolo.carlini at oracle dot com @ 2013-08-05 19:00 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=46206

Paolo Carlini <paolo.carlini at oracle dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |ASSIGNED
           Assignee|unassigned at gcc dot gnu.org      |paolo.carlini at oracle dot com
   Target Milestone|---                         |4.9.0

--- Comment #4 from Paolo Carlini <paolo.carlini at oracle dot com> ---
I have a patchlet which works for the testcase and passes testing. Let's fix
this insanity, one way or another.


^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug c++/46206] using typedef-name error with typedef name hiding struct name
  2010-10-28  1:58 [Bug c++/46206] New: using typedef-name error with typedef name hiding struct name nathan.keynes at oracle dot com
                   ` (3 preceding siblings ...)
  2013-08-05 19:00 ` paolo.carlini at oracle dot com
@ 2013-08-07 10:11 ` paolo.carlini at oracle dot com
  2013-08-09 12:05 ` paolo.carlini at oracle dot com
                   ` (6 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: paolo.carlini at oracle dot com @ 2013-08-07 10:11 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=46206

Paolo Carlini <paolo.carlini at oracle dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
         Resolution|---                         |FIXED

--- Comment #5 from Paolo Carlini <paolo.carlini at oracle dot com> ---
Fixed.


^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug c++/46206] using typedef-name error with typedef name hiding struct name
  2010-10-28  1:58 [Bug c++/46206] New: using typedef-name error with typedef name hiding struct name nathan.keynes at oracle dot com
                   ` (4 preceding siblings ...)
  2013-08-07 10:11 ` paolo.carlini at oracle dot com
@ 2013-08-09 12:05 ` paolo.carlini at oracle dot com
  2014-04-22 11:36 ` jakub at gcc dot gnu.org
                   ` (5 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: paolo.carlini at oracle dot com @ 2013-08-09 12:05 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=46206

Paolo Carlini <paolo.carlini at oracle dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |NEW
         Resolution|FIXED                       |---
           Assignee|paolo.carlini at oracle dot com    |unassigned at gcc dot gnu.org

--- Comment #6 from Paolo Carlini <paolo.carlini at oracle dot com> ---
Patch reverted. For some reason, it only worked on Linux.


^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug c++/46206] using typedef-name error with typedef name hiding struct name
  2010-10-28  1:58 [Bug c++/46206] New: using typedef-name error with typedef name hiding struct name nathan.keynes at oracle dot com
                   ` (5 preceding siblings ...)
  2013-08-09 12:05 ` paolo.carlini at oracle dot com
@ 2014-04-22 11:36 ` jakub at gcc dot gnu.org
  2014-07-16 13:28 ` jakub at gcc dot gnu.org
                   ` (4 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: jakub at gcc dot gnu.org @ 2014-04-22 11:36 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=46206

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|4.9.0                       |4.9.1

--- Comment #7 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
GCC 4.9.0 has been released


^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug c++/46206] using typedef-name error with typedef name hiding struct name
  2010-10-28  1:58 [Bug c++/46206] New: using typedef-name error with typedef name hiding struct name nathan.keynes at oracle dot com
                   ` (6 preceding siblings ...)
  2014-04-22 11:36 ` jakub at gcc dot gnu.org
@ 2014-07-16 13:28 ` jakub at gcc dot gnu.org
  2014-10-30 10:39 ` jakub at gcc dot gnu.org
                   ` (3 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: jakub at gcc dot gnu.org @ 2014-07-16 13:28 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=46206

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|4.9.1                       |4.9.2

--- Comment #8 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
GCC 4.9.1 has been released.


^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug c++/46206] using typedef-name error with typedef name hiding struct name
  2010-10-28  1:58 [Bug c++/46206] New: using typedef-name error with typedef name hiding struct name nathan.keynes at oracle dot com
                   ` (7 preceding siblings ...)
  2014-07-16 13:28 ` jakub at gcc dot gnu.org
@ 2014-10-30 10:39 ` jakub at gcc dot gnu.org
  2015-06-26 20:01 ` jakub at gcc dot gnu.org
                   ` (2 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: jakub at gcc dot gnu.org @ 2014-10-30 10:39 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=46206

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|4.9.2                       |4.9.3

--- Comment #9 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
GCC 4.9.2 has been released.


^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug c++/46206] using typedef-name error with typedef name hiding struct name
  2010-10-28  1:58 [Bug c++/46206] New: using typedef-name error with typedef name hiding struct name nathan.keynes at oracle dot com
                   ` (8 preceding siblings ...)
  2014-10-30 10:39 ` jakub at gcc dot gnu.org
@ 2015-06-26 20:01 ` jakub at gcc dot gnu.org
  2015-06-26 20:30 ` jakub at gcc dot gnu.org
  2020-07-08 15:59 ` redi at gcc dot gnu.org
  11 siblings, 0 replies; 13+ messages in thread
From: jakub at gcc dot gnu.org @ 2015-06-26 20:01 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=46206

--- Comment #10 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
GCC 4.9.3 has been released.


^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug c++/46206] using typedef-name error with typedef name hiding struct name
  2010-10-28  1:58 [Bug c++/46206] New: using typedef-name error with typedef name hiding struct name nathan.keynes at oracle dot com
                   ` (9 preceding siblings ...)
  2015-06-26 20:01 ` jakub at gcc dot gnu.org
@ 2015-06-26 20:30 ` jakub at gcc dot gnu.org
  2020-07-08 15:59 ` redi at gcc dot gnu.org
  11 siblings, 0 replies; 13+ messages in thread
From: jakub at gcc dot gnu.org @ 2015-06-26 20:30 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=46206

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|4.9.3                       |4.9.4


^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug c++/46206] using typedef-name error with typedef name hiding struct name
  2010-10-28  1:58 [Bug c++/46206] New: using typedef-name error with typedef name hiding struct name nathan.keynes at oracle dot com
                   ` (10 preceding siblings ...)
  2015-06-26 20:30 ` jakub at gcc dot gnu.org
@ 2020-07-08 15:59 ` redi at gcc dot gnu.org
  11 siblings, 0 replies; 13+ messages in thread
From: redi at gcc dot gnu.org @ 2020-07-08 15:59 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=46206

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           See Also|                            |https://gcc.gnu.org/bugzill
                   |                            |a/show_bug.cgi?id=19538
           Keywords|                            |rejects-valid

--- Comment #11 from Jonathan Wakely <redi at gcc dot gnu.org> ---
(In reply to Nathan Keynes from comment #0)
> but accepts many similar examples, including:
> class Foo
> {
>     bool a, b, c;
>     typedef struct Bar { } Bar;
>     virtual void foo(void) {
>         struct Bar bar;
>     }
> };

That is no longer accepted, since r252005. So the difference was possibly a
bug, which got fixed, and now we consistently reject both, but ...

> I'm uncertain if this is strictly legal or not per the standard, but it
> doesn't seem to make sense to accept one of these cases but not the other.

It was made legal by https://wg21.link/cwg407 (c.f. PR 19538). Both examples
should compile.

^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2020-07-08 15:59 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-10-28  1:58 [Bug c++/46206] New: using typedef-name error with typedef name hiding struct name nathan.keynes at oracle dot com
2010-10-28  2:16 ` [Bug c++/46206] " paolo.carlini at oracle dot com
2013-08-05 10:59 ` paolo.carlini at oracle dot com
2013-08-05 13:47 ` paolo.carlini at oracle dot com
2013-08-05 19:00 ` paolo.carlini at oracle dot com
2013-08-07 10:11 ` paolo.carlini at oracle dot com
2013-08-09 12:05 ` paolo.carlini at oracle dot com
2014-04-22 11:36 ` jakub at gcc dot gnu.org
2014-07-16 13:28 ` jakub at gcc dot gnu.org
2014-10-30 10:39 ` jakub at gcc dot gnu.org
2015-06-26 20:01 ` jakub at gcc dot gnu.org
2015-06-26 20:30 ` jakub at gcc dot gnu.org
2020-07-08 15:59 ` redi at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).