[llvm-bugs] [Bug 46365] New: Missing error message of "functions cannot be declared in an anonymous union"

via llvm-bugs llvm-bugs at lists.llvm.org
Wed Jun 17 08:31:33 PDT 2020


https://bugs.llvm.org/show_bug.cgi?id=46365

            Bug ID: 46365
           Summary: Missing error message of "functions cannot be declared
                    in an anonymous union"
           Product: clang
           Version: trunk
          Hardware: PC
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Frontend
          Assignee: unassignedclangbugs at nondot.org
          Reporter: haoxintu at gmail.com
                CC: llvm-bugs at lists.llvm.org, neeilans at live.com,
                    richard-llvm at metafoo.co.uk

This code test.cc, clang-trunk can not emit the error message about a function
used in an anonymous union, while in clang-10 or lower versions do.

$cat test.cc
int main(){
    static union { foo(int,int);};
    return 0;
}

$clang++-trunk -w test.cc
test.cc:2:20: error: C++ requires a type specifier for all declarations
    static union { foo(int,int);};
                   ^
1 error generated.

$clang++-10 -w test.cc
test.cc:2:20: error: C++ requires a type specifier for all declarations
    static union { foo(int,int);};
                   ^
test.cc:2:20: error: functions cannot be declared in an anonymous union
2 errors generated.

Also in GCC, it can detect the anonymous union error.

$g++ -w test.cc
est.cc: In function ‘int main()’:
test.cc:2:20: error: ISO C++ forbids declaration of ‘foo’ with no type
[-fpermissive]
    2 |     static union { foo(int,int);};
      |                    ^~~
test.cc:2:20: error: ‘int main()::<unnamed union>::foo(int, int)’ invalid; an
anonymous union can only have non-static data members [-fpermissive]

When I change line 2 into "static union {int foo(int,int);};", clang can emit
the "functions cannot be declared in an anonymous union" error, same as the
clang-10 do. 

Should clang-trunk give two error messages in the test.cc like clang-10 or it's
the enhancement behavior of clang-trunk? I guess clang-trunk might stop
emitting errors after the first error or can not detect functions used in an
anonymous union correctly.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20200617/43b4d9be/attachment.html>


More information about the llvm-bugs mailing list