<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 - Suppressing -Wduplicate-enum via pragma is less intuitive than it should be"
   href="https://bugs.llvm.org/show_bug.cgi?id=38876">38876</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Suppressing -Wduplicate-enum via pragma is less intuitive than it should be
          </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>All
          </td>
        </tr>

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

        <tr>
          <th>Severity</th>
          <td>enhancement
          </td>
        </tr>

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

        <tr>
          <th>Component</th>
          <td>-New Bugs
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>arthur.j.odwyer@gmail.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Inspired by discussion of duplicated enum values in
<a href="https://groups.google.com/a/isocpp.org/forum/#!topic/std-proposals/mpGmQBP4AqI">https://groups.google.com/a/isocpp.org/forum/#!topic/std-proposals/mpGmQBP4AqI</a>
, I decided to play around with -Wduplicate-enum.

cat >test.cc <<EOF
enum Ranges {
    CategoryX = 100,
    X1 = CategoryX,
    X2,
    X3,
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wduplicate-enum"
    DeprecatedNameX1 = X1,
    DeprecatedNameX2,
    DeprecatedNameX3,
#pragma clang diagnostic pop
};
EOF
clang++ -std=c++17 -Wduplicate-enum test.cc

The duplicate-enum warning for the pair (X2, DeprecatedNameX2) is still
printed.
The duplicate-enum warning for the pair (X3, DeprecatedNameX3) is still
printed.
However, if I change my code to:

cat >fixed.cc <<EOF
enum Ranges {
    CategoryX = 100,
    X1 = CategoryX,
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wduplicate-enum"
    X2,
    X3,
#pragma clang diagnostic pop
    DeprecatedNameX1 = X1,
    DeprecatedNameX2,
    DeprecatedNameX3,
};
EOF
clang++ -std=c++17 -Wduplicate-enum fixed.cc

then the duplicate-enum warnings are both suppressed as I'd intended.
But this is highly counter-intuitive pragma placement! I don't want to turn off
-Wduplicate-enum for the *original* X2 and X3; I want to suppress
-Wduplicate-enum warnings specifically for the *duplicates*, DeprecatedNameX2
and DeprecatedNameX3.

Ideally, I'd like my "test.cc" to continue to get warnings for duplicates of X2
*other than* DeprecatedNameX2.

At a bare minimum, I'd like my "test.cc" to compile without warnings (i.e.,
Clang should check the position of the note as well as the position of the
warning, when deciding whether to emit each diagnostic).</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>