Artifact 9711899e2fb6c4df269031eb0237e0b3622f8f7c20f478912acb8cf597bb40ac:

Ticket change [9711899e] - New ticket [f2456819] clang: Feature detection via has_feature vs has_extension. by luismachuca 2019-08-16 18:19:16.
D 2019-08-16T18:19:16.335
J foundin all
J icomment At\spresent,\ssupported\sfeatures\sin\sClang\sare\sdetected\svia\s<tt>__has_extension</tt>\sin\sconfig/clang.hpp\s,\sunlike\sin\sother\scompilers\ssuch\sas\sGCC\swhere\sthey\sare\sdetected\svia\sparsing\sof\sthe\sreported\svalues\sof\s<tt>__cplusplus</tt>\sand\sthe\scompiler's\sversion\snumber.\s\r\n\r\nThis\sis\sone\sof\stwo\sways\sof\sdetecting\sfeatures\sin\sClang:\r\n\r\n<blockquote>\r\n<b><tt>__has_feature</tt>\sand\s<tt>__has_extension</tt></b><br/>\r\n<br/>\r\n\r\nThese\sfunction-like\smacros\stake\sa\ssingle\sidentifier\sargument\sthat\sis\sthe\sname\sof\sa\sfeature.\s__has_feature\sevaluates\sto\s1\sif\sthe\sfeature\sis\sboth\ssupported\sby\sClang\sand\sstandardized\sin\sthe\scurrent\slanguage\sstandard\sor\s0\sif\snot\s(but\ssee\sbelow),\swhile\s__has_extension\sevaluates\sto\s1\sif\sthe\sfeature\sis\ssupported\sby\sClang\sin\sthe\scurrent\slanguage\s(either\sas\sa\slanguage\sextension\sor\sa\sstandard\slanguage\sfeature)\sor\s0\sif\snot.\s\r\n</blockquote>\r\n\r\n(Source:\s[https://releases.llvm.org/4.0.0/tools/clang/docs/LanguageExtensions.html#feature-checking-macros]\s)\r\n\r\nThis\sdifference\sin\simplementation\shas\smaybe\sunintended\seffects\swhen\scompiling\scode\susing\scxxomfort\sin\sClang:\scode\s(and\sthe\slibrary\sitself)\swill\sdetect\sa\scertain\sfeature\sis\savailable\sdespite\sthe\sStandard\snot\ssupporting\sor\sEmulating\sit\sand\sthus\scode\srelying\son\sthe\simplementation\sof\sthe\sbackport\scan\sfail\ssilently\sor\sgenerate\sundue\swarnings.\sOne\ssuch\sexample\sis\s<tt>explicit_cast</tt>,\swhich\swith\sall\sversions\sup\sto\s<tt>CXXOMFORT_DATE\s==\s20190215</tt>\swill\sgenerate\sthe\sfollowing\swarnings\sin\sClang++\s3.x\sand\s4.x:\r\n\r\n<verbatim>\r\n/usr/local/include/cxxomfort/impl/17-byte.hpp:156:2:\swarning:\sexplicit\sconversion\sfunctions\sare\sa\sC++11\sextension\s[-Wc++11-extensions]\r\n</verbatim>\r\n\r\nAnd\sthe\s<tt>explicit_cast</tt>\sexample\sin\scxxomfort-examples\serrors\sout\swith\smessages\ssuch\sas\sthe\sfollowing,\sapparently\sdue\sto\ssetting\sup\s"<tt>explicit_cast</tt>"\sto\sbe\s"<tt>static_cast</tt>",\swhich\sdoesn't\shave\sthe\ssame\ssemantics\sin\sC++03:\r\n\r\n<verbatim>\r\nexplicit_cast.cpp:70:12:\serror:\sno\smatching\sconversion\sfor\sstatic_cast\sfrom\s'myfoo'\sto\s'mybar'\r\n\s\s\s\sdobar(\sexplicit_cast<mybar>(foo2));\s//\s<--\sshould\swork\r\n</verbatim>\r\n\r\nOther\scxxomfort\sfeatures\smight\sbe\salso\saffected.\sMost\slikely:\s<tt>enum\sclass</tt>\semulation,\slocal\sfunction\semulation\sand\sstuff\sin\s<tt><functional></tt>.\r\n\r\n<hr/>\r\n\r\nProposed\ssolutions:\r\n\r\n<ul><li>\sDetection\sshould\stake\splace\susing\s<tt>__has_feature</tt>\sfor\sall\sStandard\sfeatures,\sand\slibrary\scode\sshould\sopt-in\saccordingly.\r\n</li><li>\sDetection\sshould\stake\splace\susing\s<tt>__has_extension</tt>\sfor\sall\sStandard\sextensions,\sand\slibrary\scode\sshould\sopt-out\saccordingly.\r\n</li><li>\sDetection\sshould\stake\splace\seither\sof\sthe\stwo\son\sa\sper-feature\sbasis,\sleft\sto\sthe\suser\swith\sa\ssensible\sdefault\sof\s<tt>__has_feature</tt>.\r\n</li>\s</ul>
J login luismachuca
J mimetype text/x-fossil-wiki
J severity Important
J status Open
J title clang:\sFeature\sdetection\svia\shas_feature\svs\shas_extension
J type Code_Defect
K f245681931009283f80ed29241d0e31313f97115
U luismachuca
Z 2de6a51325520c15fda1923ea0c3a402