]> granicus.if.org Git - clang/commitdiff
Disable -Wunique-enum for anonymous enums.
authorDavid Blaikie <dblaikie@gmail.com>
Wed, 30 May 2012 20:45:14 +0000 (20:45 +0000)
committerDavid Blaikie <dblaikie@gmail.com>
Wed, 30 May 2012 20:45:14 +0000 (20:45 +0000)
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.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@157713 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Basic/DiagnosticSemaKinds.td
lib/Sema/SemaDecl.cpp
test/SemaCXX/warn-unique-enum.cpp

index b62e3aefae1498d0b10f5fae9263784888b2dd2d..206cbe10563e4f47ecb3ac30631fde1f9a3dc7a0 100644 (file)
@@ -21,8 +21,8 @@ def warn_variables_not_in_loop_body : Warning<
   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<
index 8f991c7fe13f3dcc5fe6b5cb52b86a3781c85985..d194d9f100619717154375084bf1ec801793830e 100644 (file)
@@ -10245,6 +10245,9 @@ static void CheckForUniqueEnumValues(Sema &S, Decl **Elements,
   if (NumElements < 2)
     return;
 
+  if (!Enum->getIdentifier())
+    return;
+
   llvm::APSInt FirstVal;
 
   for (unsigned i = 0; i != NumElements; ++i) {
@@ -10268,9 +10271,8 @@ static void CheckForUniqueEnumValues(Sema &S, Decl **Elements,
       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();
 }
 
index ddafc16aab5d884c99965f656d1ce8fbfca77a08..7d04b1dc2ddc26de02ac328a8c2225e952679f12 100644 (file)
@@ -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}}