<html>
    <head>
      <base href="http://llvm.org/bugs/" />
    </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 --- - -Wunused-const-variable is too aggressive, shouldn't be part of "-Wall" anyway"
   href="http://llvm.org/bugs/show_bug.cgi?id=19596">19596</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>-Wunused-const-variable is too aggressive, shouldn't be part of "-Wall" anyway
          </td>
        </tr>

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

        <tr>
          <th>Version</th>
          <td>3.4
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>All
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>All
          </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>Static Analyzer
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>kremenek@apple.com
          </td>
        </tr>

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

        <tr>
          <th>CC</th>
          <td>llvmbugs@cs.uiuc.edu
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>cat >type_safe_enum.h <<EOF
#pragma once

#define ENUM_CONST(a) a,
#define ENUM_COUNT(a) +1
#define ENUM_NAME(a) #a,

#define TYPE_SAFE_ENUM(NAME, TYPE, VALUES) \
    enum class NAME : TYPE { VALUES(ENUM_CONST) }; \
    static const TYPE EnumSize_##NAME = 0 VALUES(ENUM_COUNT); \
    inline const char* EnumName(NAME a) { const char* names[] = {
VALUES(ENUM_NAME) }; return names[static_cast<TYPE>(a)]; }

EOF
cat >test.cc <<EOF

#include <string>
#include "type_safe_enum.h"

#define TABLE_ROLE_VALUES(F) \
    F(Slave) \
    F(Master)

TYPE_SAFE_ENUM(TableRole, int, TABLE_ROLE_VALUES);

TableRole g_foo = TableRole::Slave;
TableRole GetFoo() { return g_foo; }
std::string GetFooName() { return EnumName(g_foo); }

EOF
clang++ -std=c++11 -c test.cc -Wall



The above test case gives a spurious warning about the "unused const variable"
EnumSize_TableRole, even though there's nothing the programmer can do about
that.
I would like to see this warning either
(1) moved out of -Wall to preserve GCC-compatibility (I think the appropriate
place for it is -Weverything), and/or
(2) toned down so that it doesn't warn about variables generated by macro
expansions.


$ clang++ -std=c++11 -c test.cc -Wall
test.cc:7:1: warning: unused variable 'EnumSize_TableRole'
[-Wunused-const-variable]
TYPE_SAFE_ENUM(TableRole, int, TABLE_ROLE_VALUES);
^
./type_safe_enum.h:7:117: note: expanded from macro 'TYPE_SAFE_ENUM'
#define TYPE_SAFE_ENUM(NAME, TYPE, VALUES)     enum class NAME : TYPE {
VALUES(ENUM_CONST) };     static const TYPE EnumSize_##NAME = 0 VALUES...
                                                                               
                                    ^
<scratch space>:159:1: note: expanded from here
EnumSize_TableRole
^
1 warning generated.

$ clang++ --version
Apple LLVM version 5.1 (clang-503.0.38) (based on LLVM 3.4svn)
Target: x86_64-apple-darwin12.5.0
Thread model: posix</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>