[cfe-commits] r157713 - in /cfe/trunk: include/clang/Basic/DiagnosticSemaKinds.td lib/Sema/SemaDecl.cpp test/SemaCXX/warn-unique-enum.cpp
David Blaikie
dblaikie at gmail.com
Wed May 30 13:45:14 PDT 2012
Author: dblaikie
Date: Wed May 30 15:45:14 2012
New Revision: 157713
URL: http://llvm.org/viewvc/llvm-project?rev=157713&view=rev
Log:
Disable -Wunique-enum for anonymous enums.
This is a large class of false positives where anonymous enums are used to
declare constants (see Clang's Diagnostics.h for example). A small number of
true positives could probably be found in this bucket by still warning if the
anonymous enum is used in a declarator (enum { ... } x;) but so far we don't
believe this to be a source of significant benefit so I haven't bothered to
preserve those cases.
General offline review/acknowledgment by rtrieu.
Modified:
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/lib/Sema/SemaDecl.cpp
cfe/trunk/test/SemaCXX/warn-unique-enum.cpp
Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=157713&r1=157712&r2=157713&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Wed May 30 15:45:14 2012
@@ -21,8 +21,8 @@
InGroup<DiagGroup<"loop-analysis">>, DefaultIgnore;
def warn_identical_enum_values : Warning<
- "all elements of %select{anonymous enum|%1}0 are initialized with literals "
- "to value %2">, InGroup<DiagGroup<"unique-enum">>;
+ "all elements of %0 are initialized with literals to value %1">,
+ InGroup<DiagGroup<"unique-enum">>;
// Constant expressions
def err_expr_not_ice : Error<
Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=157713&r1=157712&r2=157713&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Wed May 30 15:45:14 2012
@@ -10245,6 +10245,9 @@
if (NumElements < 2)
return;
+ if (!Enum->getIdentifier())
+ return;
+
llvm::APSInt FirstVal;
for (unsigned i = 0; i != NumElements; ++i) {
@@ -10268,9 +10271,8 @@
return;
}
- bool hasIdentifier = Enum->getIdentifier();
S.Diag(Enum->getLocation(), diag::warn_identical_enum_values)
- << hasIdentifier << EnumType << FirstVal.toString(10)
+ << EnumType << FirstVal.toString(10)
<< Enum->getSourceRange();
}
Modified: cfe/trunk/test/SemaCXX/warn-unique-enum.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/warn-unique-enum.cpp?rev=157713&r1=157712&r2=157713&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/warn-unique-enum.cpp (original)
+++ cfe/trunk/test/SemaCXX/warn-unique-enum.cpp Wed May 30 15:45:14 2012
@@ -1,6 +1,6 @@
// RUN: %clang_cc1 %s -fsyntax-only -verify -Wunique-enum
enum A { A1 = 1, A2 = 1, A3 = 1 }; // expected-warning {{all elements of 'A' are initialized with literals to value 1}}
-enum { B1 = 1, B2 = 1, B3 = 1 }; // expected-warning {{all elements of anonymous enum are initialized with literals to value 1}}
+enum { B1 = 1, B2 = 1, B3 = 1 }; // no warning
enum C { C1 = true, C2 = true}; // expected-warning {{all elements of 'C' are initialized with literals to value 1}}
enum D { D1 = 5, D2 = 5L, D3 = 5UL, D4 = 5LL, D5 = 5ULL }; // expected-warning {{all elements of 'D' are initialized with literals to value 5}}
More information about the cfe-commits
mailing list