<div dir="ltr">// bleh.cpp<br><div><div>#include <iostream><br><br>enum class One : int {DUMMY_1 = 1};<br>enum class Two : unsigned int {DUMMY_2 = 1};<br>enum class Three : char {DUMMY_3 = 1};<br><br>void foo(One)<br>
{<br> std::cout << "One" << std::endl;<br>}<br>void foo(Two)<br>{<br> std::cout << "Two" << std::endl;<br>}<br>void foo(Three)<br>{<br> std::cout << "Three" << std::endl;<br>
}<br><br>int main()<br>{<br> foo(One::DUMMY_1);<br> foo(Two::DUMMY_2);<br> foo(Three::DUMMY_3);<br> return 0;<br>}<br><br>// <br><br>$ clang++ -std=c++11 bleh.cpp -o bleh<br></div><div>$ ./bleh<br></div><div>
One<br>
</div><div>Two<br></div><div>Three<br></div></div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Fri, Aug 2, 2013 at 12:57 PM, Ólafur Waage <span dir="ltr"><<a href="mailto:olafurw@gmail.com" target="_blank">olafurw@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Since enums in C are just named integers, they are all of the same type. So it would be the same as doing three functions with int as the argument.<br>
<br><br></div><div class="gmail_extra"><br><br><div class="gmail_quote"><div><div class="h5">
On Fri, Aug 2, 2013 at 12:29 PM, Lizunov, Andrey E <span dir="ltr"><<a href="mailto:andrey.e.lizunov@intel.com" target="_blank">andrey.e.lizunov@intel.com</a>></span> wrote:<br></div></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div><div class="h5">
<div link="blue" vlink="purple" lang="RU">
<div>
<p class="MsoNormal"><span lang="EN-US">Hello,<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-US"><u></u> <u></u></span></p>
<p class="MsoNormal"><span lang="EN-US">I was trying to use __attribute__((overloadable)) for functions accepting enumerated types but hadn’t succeeded so far.<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-US">Clang 3.1 and 3.2 failed to compile the following example.<u></u><u></u></span></p>
<p class="MsoNormal" style="text-indent:35.4pt"><span style="font-family:"Courier New"" lang="EN-US">/* clang -x c foo.cpp */<u></u><u></u></span></p>
<p class="MsoNormal" style="margin-left:35.4pt"><span style="font-family:"Courier New"" lang="EN-US">typedef enum __One {DUMMY_1} One;<u></u><u></u></span></p>
<p class="MsoNormal" style="margin-left:35.4pt"><span style="font-family:"Courier New"" lang="EN-US">typedef enum {DUMMY_2} Two;<u></u><u></u></span></p>
<p class="MsoNormal" style="margin-left:35.4pt"><span style="font-family:"Courier New"" lang="EN-US">enum Three {DUMMY_3};<u></u><u></u></span></p>
<p class="MsoNormal" style="margin-left:35.4pt"><span style="font-family:"Courier New"" lang="EN-US"><u></u> <u></u></span></p>
<p class="MsoNormal" style="margin-left:35.4pt"><span style="font-family:"Courier New"" lang="EN-US">__attribute__((overloadable)) void foo(One);<u></u><u></u></span></p>
<p class="MsoNormal" style="margin-left:35.4pt"><span style="font-family:"Courier New"" lang="EN-US">__attribute__((overloadable)) void foo(Two);<u></u><u></u></span></p>
<p class="MsoNormal" style="margin-left:35.4pt"><span style="font-family:"Courier New"" lang="EN-US">__attribute__((overloadable)) void foo(enum Three);<u></u><u></u></span></p>
<p class="MsoNormal" style="margin-left:35.4pt"><span style="font-family:"Courier New"" lang="EN-US"><u></u> <u></u></span></p>
<p class="MsoNormal" style="margin-left:35.4pt"><span style="font-family:"Courier New"" lang="EN-US">int main()<u></u><u></u></span></p>
<p class="MsoNormal" style="margin-left:35.4pt"><span style="font-family:"Courier New"" lang="EN-US">{<u></u><u></u></span></p>
<p class="MsoNormal" style="margin-left:35.4pt"><span style="font-family:"Courier New"" lang="EN-US"> foo(DUMMY_1);<u></u><u></u></span></p>
<p class="MsoNormal" style="margin-left:35.4pt"><span style="font-family:"Courier New"" lang="EN-US"> return 0;<u></u><u></u></span></p>
<p class="MsoNormal" style="margin-left:35.4pt"><span style="font-family:"Courier New"" lang="EN-US">}
<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-US">Providing me with the following error message:</span><span lang="EN-US"><u></u><u></u></span></p>
<p class="MsoNormal" style="margin-left:35.4pt"><span style="font-family:"Courier New"" lang="EN-US">$ clang -x c foo.cpp<u></u><u></u></span></p>
<p class="MsoNormal" style="margin-left:35.4pt"><span style="font-family:"Courier New"" lang="EN-US">foo.cpp:22:3: error: call to 'foo' is ambiguous<u></u><u></u></span></p>
<p class="MsoNormal" style="margin-left:35.4pt"><span style="font-family:"Courier New"" lang="EN-US"> foo(DUMMY_1);<u></u><u></u></span></p>
<p class="MsoNormal" style="margin-left:35.4pt"><span style="font-family:"Courier New"" lang="EN-US"> ^~~<u></u><u></u></span></p>
<p class="MsoNormal" style="margin-left:35.4pt"><span style="font-family:"Courier New"" lang="EN-US">foo.cpp:16:36: note: candidate function<u></u><u></u></span></p>
<p class="MsoNormal" style="margin-left:35.4pt"><span style="font-family:"Courier New"" lang="EN-US">__attribute__((overloadable)) void foo(One);<u></u><u></u></span></p>
<p class="MsoNormal" style="margin-left:35.4pt"><span style="font-family:"Courier New"" lang="EN-US"> ^<u></u><u></u></span></p>
<p class="MsoNormal" style="margin-left:35.4pt"><span style="font-family:"Courier New"" lang="EN-US">foo.cpp:17:36: note: candidate function<u></u><u></u></span></p>
<p class="MsoNormal" style="margin-left:35.4pt"><span style="font-family:"Courier New"" lang="EN-US">__attribute__((overloadable)) void foo(Two);<u></u><u></u></span></p>
<p class="MsoNormal" style="margin-left:35.4pt"><span style="font-family:"Courier New"" lang="EN-US"> ^<u></u><u></u></span></p>
<p class="MsoNormal" style="margin-left:35.4pt"><span style="font-family:"Courier New"" lang="EN-US">foo.cpp:18:36: note: candidate function<u></u><u></u></span></p>
<p class="MsoNormal" style="margin-left:35.4pt"><span style="font-family:"Courier New"" lang="EN-US">__attribute__((overloadable)) void foo(enum Three);<u></u><u></u></span></p>
<p class="MsoNormal" style="margin-left:35.4pt"><span style="font-family:"Courier New"" lang="EN-US"> ^<u></u><u></u></span></p>
<p class="MsoNormal" style="margin-left:35.4pt"><span style="font-family:"Courier New"" lang="EN-US">1 error generated.<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-US">While with “-x c++” both versions of Clang compiled it successfully (failed to link though).</span><span lang="EN-US"><u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-US"><u></u> <u></u></span></p>
<p class="MsoNormal"><span lang="EN-US">According to </span><a href="http://clang.llvm.org/docs/LanguageExtensions.html#function-overloading-in-c" target="_blank"><span lang="EN-US">http://clang.llvm.org/docs/LanguageExtensions.html#function-overloading-in-c</span></a><span lang="EN-US">
overloadable attribute is an analogue for C++ function overloading in C.<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-US">So, is it a bug in the Clang or I didn’t understand/consider something?<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-US"><u></u> <u></u></span></p>
<p class="MsoNormal"><span lang="EN-US"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-size:16.0pt;font-family:"Brush Script MT";color:#7030a0" lang="EN-US">BR,<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:16.0pt;font-family:"Brush Script MT";color:#7030a0" lang="EN-US">Andrey Lizunov<u></u><u></u></span></p>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<p><br>
--------------------------------------------------------------------<br>
Closed Joint Stock Company Intel A/O<br>
Registered legal address: Krylatsky Hills Business Park, <br>
17 Krylatskaya Str., Bldg 4, Moscow 121614, <br>
Russian Federation</p>
<p>This e-mail and any attachments may contain confidential material for<br>
the sole use of the intended recipient(s). Any review or distribution<br>
by others is strictly prohibited. If you are not the intended<br>
recipient, please contact the sender and delete all copies.</p></div>
<br></div></div>_______________________________________________<br>
cfe-dev mailing list<br>
<a href="mailto:cfe-dev@cs.uiuc.edu" target="_blank">cfe-dev@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev</a><br>
<br></blockquote></div><br></div>
</blockquote></div><br></div>