[llvm-bugs] [Bug 50751] New: False-positive -Wnon-c-typedef-for-linkage, pre-C++20

via llvm-bugs llvm-bugs at lists.llvm.org
Thu Jun 17 05:32:27 PDT 2021


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

            Bug ID: 50751
           Summary: False-positive -Wnon-c-typedef-for-linkage, pre-C++20
           Product: clang
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: C++
          Assignee: unassignedclangbugs at nondot.org
          Reporter: maltsevm at gmail.com
                CC: blitzrakete at gmail.com, dgregor at apple.com,
                    erik.pilkington at gmail.com, llvm-bugs at lists.llvm.org,
                    richard-llvm at metafoo.co.uk

Clang emits a warning when an unnamed class used in a typedef contains
constructs that are not compatible with pure C:

$ cat test.cpp
typedef struct {
    void foo();
} X;

$ clang -std=c++17 -c test.cpp
<source>:1:15: warning: anonymous non-C-compatible type given name for linkage
purposes by typedef declaration; add a tag name here
[-Wnon-c-typedef-for-linkage]
typedef struct {
              ^
               X
<source>:2:5: note: type is not C-compatible due to this member declaration
    void foo();
    ^~~~~~~~~~
<source>:3:3: note: type is given name 'X' for linkage purposes by this typedef
declaration
} X;
  ^
1 warning generated.
Compiler returned: 0

When compiling with -pedantic-errors this warning is converted into an error.

The warning is based on a change in the C++ standard introduced by the C++20
proposal P1766. As the C++20 standard suggests ([diff.cpp17.dcl.dcl]/1), the
code is valid in C++17 and earlier versions:

"Affected subclause: 9.2.3
Change: Unnamed classes with a typedef name for linkage purposes can contain
only C-compatible constructs.
Rationale: Necessary for implementability.
Effect on original feature: Valid C++ 2017 code may be ill-formed in this
International Standard.

typedef struct {
  void f() {}
} S;"

This should not be a "pedantic-error" prior to C++20.

-- 
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/20210617/6d5bebf3/attachment.html>


More information about the llvm-bugs mailing list