<div dir="ltr"><div dir="ltr">On Tue, 26 May 2020 at 20:12, Akira Hatanaka via cfe-commits <<a href="mailto:cfe-commits@lists.llvm.org">cfe-commits@lists.llvm.org</a>> wrote:<br></div><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div style="overflow-wrap: break-word;"><div dir="auto" style="overflow-wrap: break-word;"><div><blockquote type="cite"><div>On May 20, 2020, at 5:53 PM, Richard Smith <<a href="mailto:richard@metafoo.co.uk" target="_blank">richard@metafoo.co.uk</a>> wrote:</div><br><div><div dir="ltr" style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration:none"><div dir="ltr">On Wed, 20 May 2020 at 16:30, Akira Hatanaka via cfe-commits <<a href="mailto:cfe-commits@lists.llvm.org" target="_blank">cfe-commits@lists.llvm.org</a>> wrote:<br></div><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div><div dir="auto">Hi Richard,<div><br></div><div>It looks like this patch will reject the following code, which used to compile fine:</div><div><br></div><div>$ cat test.cpp</div><div><div style="margin:0px;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo"><span style="font-variant-ligatures:no-common-ligatures">#include <CoreFoundation/CoreFoundation.h></span></div><div style="margin:0px;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;min-height:13px"><span style="font-variant-ligatures:no-common-ligatures"></span><br></div><div style="margin:0px;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo"><span style="font-variant-ligatures:no-common-ligatures">typedef CF_ENUM(unsigned, TestEnum) {</span></div><div style="margin:0px;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo"><span style="font-variant-ligatures:no-common-ligatures"> <span> </span>A = 2,</span></div><div style="margin:0px;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo"><span style="font-variant-ligatures:no-common-ligatures"> <span> </span>B = 3,</span></div><div style="margin:0px;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo"><span style="font-variant-ligatures:no-common-ligatures">};</span></div></div><div><br></div><div>$ clang++ -std=c++11 -c test.cpp</div><div><br></div><div><div style="margin:0px;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo"><span style="font-variant-ligatures:no-common-ligatures"><b>test.cpp:3:9:<span> </span></b></span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(202,51,35)"><b>error:<span> </span></b></span><span style="font-variant-ligatures:no-common-ligatures"><b>non-defining declaration of enumeration with a fixed underlying type is only permitted as a standalone declaration; missing list of enumerators? [-Welaborated-enum-base]</b></span></div><div style="margin:0px;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo"><span style="font-variant-ligatures:no-common-ligatures">typedef CF_ENUM(unsigned, TestEnum) {</span></div><div style="margin:0px;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(57,192,38)"><br></div><div>The macro is defined in CFAvailability.h:</div><div><br></div><div><a href="https://opensource.apple.com/source/CF/CF-855.17/CFAvailability.h.auto.html" target="_blank">https://opensource.apple.com/source/CF/CF-855.17/CFAvailability.h.auto.html</a></div><div><br></div><div>What’s the best way to fix this?</div></div></div></div></blockquote><div><br></div><div>Assuming this macro is always preceded by 'typedef', how about this:</div><div><br></div><div>-#define CF_ENUM(_type, _name) enum _name : _type _name; enum _name : _type<br></div><div><div>+#define CF_ENUM(_type, _name) int _dummy_##_name; enum _name : _type _name; typedef enum _name _name; enum _name : _type<br></div><div><br></div><div>Or this:</div><div><br></div><div>+#ifdef __cplusplus<br></div><div> #define CF_ENUM(_type, _name) int _dummy_##_name; enum _name : _type<br></div><div></div><div>+#else<br></div><div><div> #define CF_ENUM(_type, _name) enum _name : _type _name; enum _name : _type<br></div><div>+#endif</div></div><div><br></div><div>(One wonders why the 'typedef' is not part of the macro definition.)</div></div></div></div></div></blockquote><div><br></div><div>Thanks! Is there a way to avoid the dummy typedef so that it doesn’t show up in completions and stuff or some way in C++ to undef the typedef? </div></div></div></div></blockquote><div><br></div><div>A typedef keyword always introduces a typedef, there's no way to remove the typedef again afterwards, and there's no way for the typedef to be for the enum type in valid C++ code. So I think the only option is for it to be a typedef for some other type. You could redeclare some typedef you already know to be in scope:</div><div><br></div><div>#define CF_ENUM(_type, _name) size_t size_t; enum _name : _type</div><div><br></div><div>... but that would do surprising things if it appeared anywhere other than at global namespace scope.</div><div><br></div><div>Perhaps you could add an availability / deprecated attribute to hide the typedef from completion (plus the 'unused' attribute to avoid warnings about it not being used).</div><div><br></div><div>Alternatively you could use a _Pragma to temporarily turn off the clang error for the invalid enum forward declaration, but presumably it would be preferable to make the code valid rather than merely get clang to continue accepting it?</div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div style="overflow-wrap: break-word;"><div dir="auto" style="overflow-wrap: break-word;"><div><blockquote type="cite"><div><div dir="ltr" style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration:none"><div class="gmail_quote"><div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div><div dir="auto"><div><div><blockquote type="cite"><div></div></blockquote></div></div></div></div></blockquote></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div><div dir="auto"><div><div><blockquote type="cite"><div>On May 11, 2020, at 1:37 PM, Richard Smith via cfe-commits <<a href="mailto:cfe-commits@lists.llvm.org" target="_blank">cfe-commits@lists.llvm.org</a>> wrote:</div><br><div><div dir="ltr" style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration:none"><div dir="ltr">On Mon, 11 May 2020 at 06:37, Hans Wennborg via cfe-commits <<a href="mailto:cfe-commits@lists.llvm.org" target="_blank">cfe-commits@lists.llvm.org</a>> wrote:<br></div><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">On Sat, May 9, 2020 at 4:32 AM Richard Smith via cfe-commits<br><<a href="mailto:cfe-commits@lists.llvm.org" target="_blank">cfe-commits@lists.llvm.org</a>> wrote:<br>><br>><br>> Author: Richard Smith<br>> Date: 2020-05-08T19:32:00-07:00<br>> New Revision: c90e198107431f64b73686bdce31c293e3380ac7<br>><br>> URL:<span> </span><a href="https://github.com/llvm/llvm-project/commit/c90e198107431f64b73686bdce31c293e3380ac7" rel="noreferrer" target="_blank">https://github.com/llvm/llvm-project/commit/c90e198107431f64b73686bdce31c293e3380ac7</a><br>> DIFF:<span> </span><a href="https://github.com/llvm/llvm-project/commit/c90e198107431f64b73686bdce31c293e3380ac7.diff" rel="noreferrer" target="_blank">https://github.com/llvm/llvm-project/commit/c90e198107431f64b73686bdce31c293e3380ac7.diff</a><br>><br>> LOG: Fix parsing of enum-base to follow C++11 rules.<br>><br>> Previously we implemented non-standard disambiguation rules to<br>> distinguish an enum-base from a bit-field but otherwise treated a :<br>> after an elaborated-enum-specifier as introducing an enum-base. That<br>> misparses various examples (anywhere an elaborated-type-specifier can<br>> appear followed by a colon, such as within a ternary operator or<br>> _Generic).<br>><br>> We now implement the C++11 rules, with the old cases accepted as<br>> extensions where that seemed reasonable. These amount to:<br>>  * an enum-base must always be accompanied by an enum definition (except<br>>    in a standalone declaration of the form 'enum E : T;')<br>>  * in a member-declaration, 'enum E :' always introduces an enum-base,<br>>    never a bit-field<br>>  * in a type-specifier (or similar context), 'enum E :' is not<br>>    permitted; the colon means whatever else it would mean in that<br>>    context.<br>><br>> Fixed underlying types for enums are also permitted in Objective-C and<br>> under MS extensions, plus as a language extension in all other modes.<br>> The behavior in ObjC and MS extensions modes is unchanged (but the<br>> bit-field disambiguation is a bit better); remaining language modes<br>> follow the C++11 rules.<br>><br>> Fixes PR45726, PR39979, PR19810, PR44941, and most of PR24297, plus C++<br>> core issues 1514 and 1966.<br><br>Hello from Chromium :-)<br><br>We saw new errors from some code in a header that looked like this:<br><br> <span> </span>// Adapted from NSPathUtilities.h and NSObjCRuntime.h.<br> <span> </span>typedef enum NSSearchPathDirectory : unsigned long NSSearchPathDirectory;<br><br>For us we think the enum itself is enough, so we'll fix it by dropping<br>the typedef, but this raised the question of how your change affects<br>the Mac system headers. IIUC your change makes an exception for Obj-C,<br>but the headers can be used from regular C/C++ too. Do you think there<br>might be issues there?<br></blockquote><div><br></div><div>The errors are DefaultError ExtWarns, so they will be suppressed by default in system headers. Even then:</div><div> * In Objective-C (and Objective-C++), the prior rule is unchanged.</div><div> * In (non-Objective) C++11 onwards, we now enforce the standard rules. (System headers should ideally be valid code, but if not, the system header exclusion will kick in. And the errors can be disabled by warning flag in user code written against old Clang.)</div><div> * In any other language mode, system headers should really not be using this functionality, since it's a non-standard language extension, and not supported by (for example) GCC. (With the same provisos as in the prior bullet.)</div><div><br></div><div>We can make the C++ side of things more permissive if necessary, but I'm hopeful that we will be able to enforce the standard rules by default in this instance.</div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">(See<span> </span><a href="https://chromium-review.googlesource.com/c/chromium/src/+/2193673" rel="noreferrer" target="_blank">https://chromium-review.googlesource.com/c/chromium/src/+/2193673</a><br>for the Chromium discussion.)<br>_______________________________________________<br>cfe-commits mailing list<br><a href="mailto:cfe-commits@lists.llvm.org" target="_blank">cfe-commits@lists.llvm.org</a><br><a href="https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits" rel="noreferrer" target="_blank">https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits</a><br></blockquote></div></div><span style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration:none;float:none;display:inline">_______________________________________________</span><br style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration:none"><span style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration:none;float:none;display:inline">cfe-commits mailing list</span><br style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration:none"><a href="mailto:cfe-commits@lists.llvm.org" style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px" target="_blank">cfe-commits@lists.llvm.org</a><br style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration:none"><a href="https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits" style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px" target="_blank">https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits</a></div></blockquote></div><br></div></div></div>_______________________________________________<br>cfe-commits mailing list<br><a href="mailto:cfe-commits@lists.llvm.org" target="_blank">cfe-commits@lists.llvm.org</a><br><a href="https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits" rel="noreferrer" target="_blank">https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits</a></blockquote></div></div></div></blockquote></div><br></div></div>_______________________________________________<br>
cfe-commits mailing list<br>
<a href="mailto:cfe-commits@lists.llvm.org" target="_blank">cfe-commits@lists.llvm.org</a><br>
<a href="https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits" rel="noreferrer" target="_blank">https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits</a><br>
</blockquote></div></div>