<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - False-positive -Wnon-c-typedef-for-linkage, pre-C++20"
   href="https://bugs.llvm.org/show_bug.cgi?id=50751">50751</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>False-positive -Wnon-c-typedef-for-linkage, pre-C++20
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>clang
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>trunk
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>Linux
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>normal
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>C++
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedclangbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>maltsevm@gmail.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>blitzrakete@gmail.com, dgregor@apple.com, erik.pilkington@gmail.com, llvm-bugs@lists.llvm.org, richard-llvm@metafoo.co.uk
          </td>
        </tr></table>
      <p>
        <div>
        <pre>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.</pre>
        </div>
      </p>


      <hr>
      <span>You are receiving this mail because:</span>

      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>