[Bug c++/96145] New: Weird output in compiling a typedef union as a function return type

haoxintu at gmail dot com gcc-bugzilla@gcc.gnu.org
Fri Jul 10 08:16:41 GMT 2020


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

            Bug ID: 96145
           Summary: Weird output in compiling a typedef union as a
                    function return type
           Product: gcc
           Version: 11.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: haoxintu at gmail dot com
  Target Milestone: ---

Hi, all.

This code, test.cc, uses a typedef name of a union as a return type of a
function, the GCC compiled output might be weird.

$cat test.cc
typedef union{} typedef_union;
typename :: typedef_union foo1 () {} 

$g++ -w test.cc
test.cc:2:13: error: 'class' tag used in naming 'union typedef_union'
[-fpermissive]
    2 | typename :: typedef_union foo1 () {}
      |             ^~~~~~~~~~~~~
test.cc:1:17: note: 'union typedef_union' was previously declared here
    1 | typedef union{} typedef_union;
      |                 ^~~~~~~~~~~~~

Two things might be weird:

1. This code is a valid code I guess. Other mainstream compilers (I test this
in clang, ice, and mvsc) accept this by default, although the error can
disappear when adding "-fpermissive" option. Maybe is this a reject-valid
issue?

2. The output "class" tag is wrong. I don't use the "class" keyword in this
small code. Maybe is this a diagnostic issue?

I report this because of the related discussions in llvm:
https://bugs.llvm.org/show_bug.cgi?id=46645

Every version from 4.0 onwards behaves the same (I didn't test anything older).

Thanks,
Haoxin


More information about the Gcc-bugs mailing list