<br><br><div class="gmail_quote">On Wed, May 30, 2012 at 8:23 PM, Jordan Rose <span dir="ltr"><<a href="mailto:jordan_rose@apple.com" target="_blank">jordan_rose@apple.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div style="word-wrap:break-word"><br><div><div>On May 30, 2012, at 10:43 AM, David Blaikie <<a href="mailto:dblaikie@gmail.com" target="_blank">dblaikie@gmail.com</a>> wrote:</div><br><blockquote type="cite"><br><br>
<div class="gmail_quote">On Tue, May 29, 2012 at 6:01 PM, Richard Trieu <span dir="ltr"><<a href="mailto:rtrieu@google.com" target="_blank">rtrieu@google.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

Author: rtrieu<br>
Date: Tue May 29 20:01:11 2012<br>
New Revision: 157666<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=157666&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=157666&view=rev</a><br>
Log:<br>
Add new -Wunique-enum which will warn on enums which all elements have the<br>
same value and were initialized with literals.  </blockquote><div><br></div><div>This currently produces a false positive on some anonymous-enum'd constants in Diagnostic.h:635:<br><br><pre style="font-size:medium">  <b><font color="#228B22">enum</font></b> {
    <i><font color="#B22222">/// MaxArguments - The maximum number of arguments we can hold. We currently
</font></i>    <i><font color="#B22222">/// only support up to 10 arguments (%0-%9).  A single diagnostic with more
</font></i>    <i><font color="#B22222">/// than that almost certainly has to be simplified anyway.
</font></i>    MaxArguments = 10,

    <i><font color="#B22222">/// MaxRanges - The maximum number of ranges we can hold.
</font></i>    MaxRanges = 10,

    <i><font color="#B22222">/// MaxFixItHints - The maximum number of ranges we can hold.
</font></i>    MaxFixItHints = 10
  };

<span style="font-family:arial;font-size:small;white-space:normal">Perhaps we should ignore this warning if the enum is unnamed? Or specifically if it's both unnamed and has no instances (so it could still fire on "enum { x, y = 0 } a, b;")<br>

<br>Since this warning is on by default, this breaks a self-host Clang -Werror build.</span></pre></div></div></blockquote></div><div>Mac OS X frameworks use anonymous enums for constants in order to have the store type be word-sized:</div>
<div><br></div><div><pre style="margin-right:0.333em;color:rgb(102,102,102);font-size:13px;margin-left:0.5em;font-family:Courier,Consolas,monospace;margin-top:0px">enum {
   <a href="https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Classes/NSString_Class/Reference/NSString.html#//apple_ref/doc/c_ref/NSCaseInsensitiveSearch" style="color:rgb(0,51,102);text-decoration:none" target="_blank">NSCaseInsensitiveSearch</a> = 1,
   <a href="https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Classes/NSString_Class/Reference/NSString.html#//apple_ref/doc/c_ref/NSLiteralSearch" style="color:rgb(0,51,102);text-decoration:none" target="_blank">NSLiteralSearch</a> = 2,
   <a href="https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Classes/NSString_Class/Reference/NSString.html#//apple_ref/doc/c_ref/NSBackwardsSearch" style="color:rgb(0,51,102);text-decoration:none" target="_blank">NSBackwardsSearch</a> = 4,
   <a href="https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Classes/NSString_Class/Reference/NSString.html#//apple_ref/doc/c_ref/NSAnchoredSearch" style="color:rgb(0,51,102);text-decoration:none" target="_blank">NSAnchoredSearch</a> = 8,
   <a href="https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Classes/NSString_Class/Reference/NSString.html#//apple_ref/doc/c_ref/NSNumericSearch" style="color:rgb(0,51,102);text-decoration:none" target="_blank">NSNumericSearch</a> = 64,
   <a href="https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Classes/NSString_Class/Reference/NSString.html#//apple_ref/doc/c_ref/NSDiacriticInsensitiveSearch" style="color:rgb(0,51,102);text-decoration:none" target="_blank">NSDiacriticInsensitiveSearch</a> = 128,
   <a href="https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Classes/NSString_Class/Reference/NSString.html#//apple_ref/doc/c_ref/NSWidthInsensitiveSearch" style="color:rgb(0,51,102);text-decoration:none" target="_blank">NSWidthInsensitiveSearch</a> = 256,
   <a href="https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Classes/NSString_Class/Reference/NSString.html#//apple_ref/doc/c_ref/NSForcedOrderingSearch" style="color:rgb(0,51,102);text-decoration:none" target="_blank">NSForcedOrderingSearch</a> = 512,
   <a href="https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Classes/NSString_Class/Reference/NSString.html#//apple_ref/doc/c_ref/NSRegularExpressionSearch" style="color:rgb(0,51,102)" target="_blank">NSRegularExpressionSearch</a> = 1024
};</pre><pre style="margin-right:0.333em;color:rgb(102,102,102);font-size:13px;margin-left:0.5em;font-family:Courier,Consolas,monospace;margin-top:0px">typedef NSUInteger NSStringCompareOptions;</pre><div>It's not likely that all options here will be the same, but then I would have said the same about enums in general. I don't have a strong opinion, but it's possible we should just change Diagnostic.h to use separate enums. (How common is it to group semi-related constants in an enum?)</div>
<span class="HOEnZb"><font color="#888888"><div><br></div><div>Jordan</div><div><div style="font-size:13px;font-family:'Lucida Grande',Geneva,Helvetica,Arial,sans-serif"></div></div></font></span></div><br></div></blockquote>
<div><br>I am not too C savvy, but I seem to recall that C is not as lenient as C++ and does not treat "int const" as being a compile-time constant, while #define and enums really are; so I would expect to see more anonymous enums in C (because #define is evil, isn't it ?)...<br>
<br>I agree it could be split in multiple enums, but having this warning on by default in C might provoke more issues than it does on C++ code bases.<br><br>-- Matthieu. <br></div></div>