[LLVMbugs] [Bug 19596] New: -Wunused-const-variable is too aggressive, shouldn't be part of "-Wall" anyway

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Mon Apr 28 22:11:37 PDT 2014


http://llvm.org/bugs/show_bug.cgi?id=19596

            Bug ID: 19596
           Summary: -Wunused-const-variable is too aggressive, shouldn't
                    be part of "-Wall" anyway
           Product: clang
           Version: 3.4
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P
         Component: Static Analyzer
          Assignee: kremenek at apple.com
          Reporter: arthur.j.odwyer at gmail.com
                CC: llvmbugs at cs.uiuc.edu
    Classification: Unclassified

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

-- 
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/20140429/64c2f3a9/attachment.html>


More information about the llvm-bugs mailing list