From: David Blaikie Date: Wed, 30 May 2012 20:45:14 +0000 (+0000) Subject: Disable -Wunique-enum for anonymous enums. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=abe21e36d789cfe800562a1e889738addfd2ac5b;p=clang 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. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@157713 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/Basic/DiagnosticSemaKinds.td b/include/clang/Basic/DiagnosticSemaKinds.td index b62e3aefae..206cbe1056 100644 --- a/include/clang/Basic/DiagnosticSemaKinds.td +++ b/include/clang/Basic/DiagnosticSemaKinds.td @@ -21,8 +21,8 @@ def warn_variables_not_in_loop_body : Warning< InGroup>, DefaultIgnore; def warn_identical_enum_values : Warning< - "all elements of %select{anonymous enum|%1}0 are initialized with literals " - "to value %2">, InGroup>; + "all elements of %0 are initialized with literals to value %1">, + InGroup>; // Constant expressions def err_expr_not_ice : Error< diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp index 8f991c7fe1..d194d9f100 100644 --- a/lib/Sema/SemaDecl.cpp +++ b/lib/Sema/SemaDecl.cpp @@ -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(); } diff --git a/test/SemaCXX/warn-unique-enum.cpp b/test/SemaCXX/warn-unique-enum.cpp index ddafc16aab..7d04b1dc2d 100644 --- a/test/SemaCXX/warn-unique-enum.cpp +++ b/test/SemaCXX/warn-unique-enum.cpp @@ -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}}