{"id":194,"date":"2021-07-02T00:29:37","date_gmt":"2021-07-01T16:29:37","guid":{"rendered":"https:\/\/blog.cauchyschwarz.com\/?p=194"},"modified":"2021-07-02T00:29:40","modified_gmt":"2021-07-01T16:29:40","slug":"c%e8%b8%a9%e5%9d%91%e7%ac%94%e8%ae%b0","status":"publish","type":"post","link":"https:\/\/blog.cauchyschwarz.com\/?p=194","title":{"rendered":"C++\u8e29\u5751\u7b14\u8bb0"},"content":{"rendered":"\n<ol class=\"wp-block-list\"><li><a href=\"https:\/\/stackoverflow.com\/questions\/10833188\/is-it-possible-to-pass-a-stringstream-as-a-function-parameter\">ostringstream\u7684\u5f15\u7528\u4f5c\u4e3a\u51fd\u6570\u53c2\u6570\u7684\u5751<\/a><br>\u60f3\u7740\u7528ostringstream\u7684\u5f15\u7528\u6765\u641e\u51e0\u4e2ajson\u7684\u5de5\u5177\u51fd\u6570\uff0c\u5c31\u50cf\u4e0b\u9762\u8fd9\u6837<\/li><\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>    template &lt;class T&gt;\n    void json_start(std::ostringstream &amp;oss, const char *key, T val) {\n        oss &lt;&lt; \"{\" &lt;&lt; key &lt;&lt; val;\n    }<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u4f1a\u62a5\u9519\uff1a<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p>error: no match for \u2018operator&lt;&lt;\u2019 in \u2018oss &lt;&lt; &#8220;{&#8220;\u2019<\/p><\/blockquote>\n\n\n\n<ol class=\"wp-block-list\" start=\"2\"><li>put_time\u51fd\u6570<\/li><li><code>non-const references to rvalues<\/code>\u7684\u542b\u4e49<br>\u4e3a\u4e86\u9632\u6b62\u4f60\u5199\u4e00\u4e2a\u51fd\u6570\u53c2\u6570\u4e3a\u5f15\u7528\u7684\u51fd\u6570\uff0c\u7136\u540e\u4e0d\u5c0f\u5fc3\u4f20\u4e86\u4e00\u4e2a\u517c\u5bb9\u7684\u7c7b\u578b\u8fdb\u53bb\uff0c\u8fd9\u4e2a\u7c7b\u578b\u81ea\u52a8\u8f6c\u4e3a\u4e86\u51fd\u6570\u53c2\u6570\u7684\u7c7b\u578b\uff0c\u4f46\u662f\u8f6c\u6362\u4e86\u4e4b\u540e\u5374\u53d8\u6210\u4e86\u4e00\u4e2a\u53f3\u503c\uff0c\u4f60\u5e76\u6ca1\u6709\u8fbe\u5230\u60f3\u8981\u7684\u901a\u8fc7\u8fd9\u4e2a\u51fd\u6570\u53bb\u6539\u53d8\u8fd9\u4e2a\u4f20\u5165\u7684\u51fd\u6570\u53c2\u6570\u7684\u76ee\u7684\u3002<\/li><\/ol>\n\n\n\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_85 ez-toc-wrap-right counter-hierarchy ez-toc-counter ez-toc-grey ez-toc-container-direction\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Table of Contents<\/p>\n<label for=\"ez-toc-cssicon-toggle-item-6a2d56f55e6f5\" class=\"ez-toc-cssicon-toggle-label\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/label><input type=\"checkbox\"  id=\"ez-toc-cssicon-toggle-item-6a2d56f55e6f5\" checked aria-label=\"Toggle\" \/><nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-1'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/blog.cauchyschwarz.com\/?p=194\/#%E5%8F%AF%E5%8F%98%E5%8F%82%E6%95%B0%E6%A8%A1%E6%9D%BF\" >\u53ef\u53d8\u53c2\u6570\u6a21\u677f<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-1'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/blog.cauchyschwarz.com\/?p=194\/#IDE\" >IDE<\/a><ul class='ez-toc-list-level-2' ><li class='ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/blog.cauchyschwarz.com\/?p=194\/#netbeans%E8%A7%A3%E6%9E%90c11%E4%BB%A3%E7%A0%81%E6%97%B6%E6%80%BB%E6%98%AF%E6%8F%90%E9%86%92%E9%94%99%E8%AF%AF\" >netbeans\u89e3\u6790c++11\u4ee3\u7801\u65f6\u603b\u662f\u63d0\u9192\u9519\u8bef<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-1'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/blog.cauchyschwarz.com\/?p=194\/#address_sanitizer\" >address sanitizer<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-1'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/blog.cauchyschwarz.com\/?p=194\/#%E7%BC%96%E8%AF%91%E6%97%B6%E6%9C%9F%E7%9A%84%E5%8F%8D%E5%B0%84\" >\u7f16\u8bd1\u65f6\u671f\u7684\u53cd\u5c04<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-1'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/blog.cauchyschwarz.com\/?p=194\/#%E6%8C%87%E5%90%91%E6%88%90%E5%91%98%E5%8F%98%E9%87%8F%E7%9A%84%E6%8C%87%E9%92%88\" >\u6307\u5411\u6210\u5458\u53d8\u91cf\u7684\u6307\u9488<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-1'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/blog.cauchyschwarz.com\/?p=194\/#%E5%90%8E%E7%BD%AE%E8%BF%94%E5%9B%9E%E7%B1%BB%E5%9E%8Btrailing_return_types\" >\u540e\u7f6e\u8fd4\u56de\u7c7b\u578b(trailing return types)<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-1'><a class=\"ez-toc-link ez-toc-heading-8\" href=\"https:\/\/blog.cauchyschwarz.com\/?p=194\/#initializer_list%E4%B8%8D%E8%83%BD%E8%A2%AB%E5%A4%8D%E5%88%B6\" >initializer_list\u4e0d\u80fd\u88ab\u590d\u5236<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-1'><a class=\"ez-toc-link ez-toc-heading-9\" href=\"https:\/\/blog.cauchyschwarz.com\/?p=194\/#%E4%B8%80%E4%BA%9B%E6%9C%89%E5%8A%A9%E4%BA%8E%E5%8F%91%E7%8E%B0%E4%BB%A3%E7%A0%81%E5%BC%82%E5%B8%B8%E7%9A%84%E7%BC%96%E8%AF%91%E9%80%89%E9%A1%B9\" >\u4e00\u4e9b\u6709\u52a9\u4e8e\u53d1\u73b0\u4ee3\u7801\u5f02\u5e38\u7684\u7f16\u8bd1\u9009\u9879<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-1'><a class=\"ez-toc-link ez-toc-heading-10\" href=\"https:\/\/blog.cauchyschwarz.com\/?p=194\/#%E6%8A%91%E5%88%B6%E7%BC%96%E8%AF%91warning%E7%9A%84%E5%87%A0%E7%A7%8D%E6%96%B9%E5%BC%8F\" >\u6291\u5236\u7f16\u8bd1warning\u7684\u51e0\u79cd\u65b9\u5f0f<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-1'><a class=\"ez-toc-link ez-toc-heading-11\" href=\"https:\/\/blog.cauchyschwarz.com\/?p=194\/#clang%E6%89%BE%E4%B8%8D%E5%88%B0%E5%A4%B4%E6%96%87%E4%BB%B6\" >clang\u627e\u4e0d\u5230\u5934\u6587\u4ef6<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-1'><a class=\"ez-toc-link ez-toc-heading-12\" href=\"https:\/\/blog.cauchyschwarz.com\/?p=194\/#NULL%E4%B8%8Enullptr%E7%9A%84%E5%8C%BA%E5%88%AB\" >NULL\u4e0enullptr\u7684\u533a\u522b<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-1'><a class=\"ez-toc-link ez-toc-heading-13\" href=\"https:\/\/blog.cauchyschwarz.com\/?p=194\/#placement_new\" >placement new<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-1'><a class=\"ez-toc-link ez-toc-heading-14\" href=\"https:\/\/blog.cauchyschwarz.com\/?p=194\/#Cannot_bind_packed_field\" >Cannot bind packed field<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-1'><a class=\"ez-toc-link ez-toc-heading-15\" href=\"https:\/\/blog.cauchyschwarz.com\/?p=194\/#%E9%9D%99%E6%80%81%E4%BB%A3%E7%A0%81%E6%A3%80%E6%9F%A5%E5%B7%A5%E5%85%B7\" >\u9759\u6001\u4ee3\u7801\u68c0\u67e5\u5de5\u5177<\/a><ul class='ez-toc-list-level-2' ><li class='ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-16\" href=\"https:\/\/blog.cauchyschwarz.com\/?p=194\/#scan-build\" >scan-build<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-17\" href=\"https:\/\/blog.cauchyschwarz.com\/?p=194\/#CodeChecker\" >CodeChecker<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-1'><a class=\"ez-toc-link ez-toc-heading-18\" href=\"https:\/\/blog.cauchyschwarz.com\/?p=194\/#%E7%BC%96%E8%AF%91%E5%8F%82%E6%95%B0\" >\u7f16\u8bd1\u53c2\u6570<\/a><\/li><\/ul><\/nav><\/div>\n<h1 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"%E5%8F%AF%E5%8F%98%E5%8F%82%E6%95%B0%E6%A8%A1%E6%9D%BF\"><\/span>\u53ef\u53d8\u53c2\u6570\u6a21\u677f<span class=\"ez-toc-section-end\"><\/span><\/h1>\n\n\n\n<p class=\"wp-block-paragraph\">\u51e0\u7bc7\u4e0d\u9519\u7684\u94fe\u63a5\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>https:\/\/arne-mertz.de\/2016\/11\/more-variadic-templates\/<\/li><li>https:\/\/raymii.org\/s\/snippets\/Cpp_variadic_template_recursive_example.html<\/li><li>https:\/\/kubasejdak.com\/techniques-of-variadic-templates<\/li><li>https:\/\/gist.github.com\/daniel-j-h\/c4a7788fd560e94db9f7<\/li><li>https:\/\/www.experts-exchange.com\/articles\/32502\/None-recursive-variadic-templates-with-std-initializer-list.html<\/li><li>https:\/\/en.cppreference.com\/w\/cpp\/language\/parameter_pack<\/li><\/ul>\n\n\n\n<h1 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"IDE\"><\/span>IDE<span class=\"ez-toc-section-end\"><\/span><\/h1>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"netbeans%E8%A7%A3%E6%9E%90c11%E4%BB%A3%E7%A0%81%E6%97%B6%E6%80%BB%E6%98%AF%E6%8F%90%E9%86%92%E9%94%99%E8%AF%AF\"><\/span>netbeans\u89e3\u6790c++11\u4ee3\u7801\u65f6\u603b\u662f\u63d0\u9192\u9519\u8bef<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<ol class=\"wp-block-list\"><li>\u5728\u5c5e\u6027=&gt;\u4ee3\u7801\u5e2e\u52a9=&gt;c++\u7f16\u8bd1\u5668=&gt;c++\u6807\u51c6\u9009c++11\uff1b<\/li><li>\u5728\u5c5e\u6027=&gt;\u4ee3\u7801\u5e2e\u52a9=&gt;c++\u7f16\u8bd1\u5668=&gt;\u9884\u5904\u7406\u7a0b\u5e8f\u5b9a\u4e49\u91cc\u52a0\u4e00\u4e2a<code>__cplusplus=201103L<\/code>\u7684\u5b8f\u5b9a\u4e49\uff0c\u53ef\u80fd\u662f\u4e0a\u9762\u7684c++11\u6807\u51c6\u8bbe\u7f6e\u6709bug\uff0c\u7ecf\u5e38\u4f1a\u4e0d\u751f\u6548\uff0c\u624d\u5bfc\u81f4\u9700\u8981\u518d\u52a0\u4e00\u4e2a\u5b8f\u5b9a\u4e49\u6765\u63d0\u9192IDE\u4f7f\u7528c++11\u6807\u51c6\u6765\u89e3\u6790\u3002<br>\u53c2\u8003\uff1ahttps:\/\/bz.apache.org\/netbeans\/show_bug.cgi?id=242729<\/li><\/ol>\n\n\n\n<h1 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"address_sanitizer\"><\/span>address sanitizer<span class=\"ez-toc-section-end\"><\/span><\/h1>\n\n\n\n<p class=\"wp-block-paragraph\"><a href=\"https:\/\/github.com\/google\/sanitizers\/wiki\/AddressSanitizer\">clang\u6587\u6863<\/a><br><a href=\"https:\/\/gcc.gnu.org\/onlinedocs\/gcc\/Instrumentation-Options.html\">gcc\u6587\u6863<\/a><br><a href=\"https:\/\/gist.github.com\/kishmakov\/6c186c738210c98bbe886cb861358b18\">\u5173\u4e8eso\u5e93\u548c\u53ef\u6267\u884c\u6587\u4ef6\u90fd\u4f7f\u7528address sanitizer\u65f6\u7684\u7f16\u8bd1\u95ee\u9898<\/a><br>\u4f7f\u7528so\u5e93\u65f6\u53ef\u80fd\u9047\u5230\u7684bug:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>https:\/\/reviews.llvm.org\/D33784<\/li><li>https:\/\/www.mail-archive.com\/llvm-bugs@lists.llvm.org\/msg14550.html<br>\u89e3\u51b3\u65b9\u6cd5\u662f\u7528LD_PRELOAD\u5148\u52a0\u8f7dasan\u5e93\uff0c\u518d\u52a0\u8f7d\u5e94\u7528\u7a0b\u5e8f\u6240\u9700\u7684so\u5e93\uff1ahttps:\/\/blog.csdn.net\/zqh1630\/article\/details\/103990483<br>sanitizer\u548ccuda\u6405\u5728\u4e00\u8d77\uff0c\u53ef\u80fd\u8fd8\u6709bug\uff1a<\/li><li>https:\/\/forums.developer.nvidia.com\/t\/cuda-runtime-library-and-addresssanitizer-incompatibilty\/63145<\/li><li>https:\/\/github.com\/google\/sanitizers\/issues\/629<br>\u89e3\u51b3\u65b9\u6cd5\u5c31\u662f\u8fd0\u884c\u7684\u65f6\u5019\u8bbe\u7f6e\u4e0basan\u7684\u53c2\u6570\uff1a<code>ASAN_OPTIONS=protect_shadow_gap=0<\/code>\uff0c\u7136\u800c\u5bf9\u6211\u7684\u5408\u6d41\u8fdb\u7a0b\u5e76\u6ca1\u6709\u6548\u679c\u3002\u3002\u3002cuda\u4f9d\u7136\u521d\u59cb\u5316\u51fa\u9519\u3002<br>\u7531\u4e8e\u8fd9\u4e9b\u5751\u7239\u7684\u95ee\u9898\uff0c\u6700\u540e\u8fd8\u662f\u9760valgrind\u89e3\u51b3\u4e86\u95ee\u9898\uff0c\u800cvalgrind\u4f7f\u7528\u8fc7\u7a0b\u4e2d\u4e5f\u51fa\u73b0\u4e86setrlimit\u7684\u62a5\u9519\uff0c\u89e3\u51b3\u529e\u6cd5\u5c31\u662f\u6ce8\u91ca\u6389setrlimit\u76f8\u5173\u7684\u4ee3\u7801\u3002<\/li><\/ul>\n\n\n\n<h1 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"%E7%BC%96%E8%AF%91%E6%97%B6%E6%9C%9F%E7%9A%84%E5%8F%8D%E5%B0%84\"><\/span>\u7f16\u8bd1\u65f6\u671f\u7684\u53cd\u5c04<span class=\"ez-toc-section-end\"><\/span><\/h1>\n\n\n\n<p class=\"wp-block-paragraph\">\u60f3\u8981\u679a\u4e3e\u7c7b\u91cc\u7684\u6bcf\u4e00\u4e2a\u6210\u5458\u53d8\u91cf\uff0c\u53ea\u80fd\u4f7f\u7528\u652f\u6301\u4e86\u53cd\u5c04\u7684c++17\u6216\u8005boost\u91cc\u7684fusion(\u81ea\u5df1\u5b9e\u73b0\u4e5f\u884c)\uff0c\u800c\u4e14\u8fd8\u5f97\u5199\u4e00\u53e5\u4ee3\u7801\u6765\u6ce8\u518c\u8fd9\u4e9b\u6210\u5458\u53d8\u91cf\u3002<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>https:\/\/github.com\/qicosmos\/iguana<\/li><\/ul>\n\n\n\n<h1 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"%E6%8C%87%E5%90%91%E6%88%90%E5%91%98%E5%8F%98%E9%87%8F%E7%9A%84%E6%8C%87%E9%92%88\"><\/span>\u6307\u5411\u6210\u5458\u53d8\u91cf\u7684\u6307\u9488<span class=\"ez-toc-section-end\"><\/span><\/h1>\n\n\n\n<p class=\"wp-block-paragraph\"><a href=\"https:\/\/en.cppreference.com\/w\/cpp\/language\/pointer\u6307\u5411\u6210\u5458\u53d8\u91cf\u7684\u6307\u9488\u5e76\u4e0d\u662f\u4e00\u4e2a\u6307\u5411\u67d0\u4e2a\u5185\u5b58\u5730\u5740\u7684\u6307\u9488\uff0c\u800c\u662f\u8bb0\u5f55\u7684\u7c7b\u6210\u5458\u7684\u504f\u79fb\u91cf\uff1b\">https:\/\/en.cppreference.com\/w\/cpp\/language\/pointer\u6307\u5411\u6210\u5458\u53d8\u91cf\u7684\u6307\u9488\u5e76\u4e0d\u662f\u4e00\u4e2a\u6307\u5411\u67d0\u4e2a\u5185\u5b58\u5730\u5740\u7684\u6307\u9488\uff0c\u800c\u662f\u8bb0\u5f55\u7684\u7c7b\u6210\u5458\u7684\u504f\u79fb\u91cf\uff1b<\/a><\/p>\n\n\n\n<h1 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"%E5%90%8E%E7%BD%AE%E8%BF%94%E5%9B%9E%E7%B1%BB%E5%9E%8Btrailing_return_types\"><\/span>\u540e\u7f6e\u8fd4\u56de\u7c7b\u578b(trailing return types)<span class=\"ez-toc-section-end\"><\/span><\/h1>\n\n\n\n<p class=\"wp-block-paragraph\"><a href=\"https:\/\/community.ibm.com\/community\/user\/ibmz-and-linuxone\/blogs\/fang-lu2\/2020\/03\/24\/introduction-to-the-c11-feature-trailing-return-types?lang=en\u4e3a\u4e86\u8ba9\u51fd\u6570\u7684\u8fd4\u56de\u7c7b\u578b\u7684\u5199\u6cd5\u53ef\u4ee5\u66f4generalized\uff0c\u4e8e\u662fc++11\u652f\u6301\u4e86\u8fd4\u56de\u7c7b\u578b\u540e\u7f6e\u7684\u5199\u6cd5\u3002\u8fd9\u6837\u53ef\u4ee5\u7528\u53c2\u6570\u5217\u8868\u91cc\u7684\u53d8\u91cf\u7ed3\u5408decltype\uff0c\u6765\u58f0\u660e\u4e0d\u7528\u8fd4\u56de\u7c7b\u578b\u540e\u7f6e\u5c31\u65e0\u6cd5\u8868\u793a\u7684\u8fd4\u56de\u7c7b\u578b\u3002\">https:\/\/community.ibm.com\/community\/user\/ibmz-and-linuxone\/blogs\/fang-lu2\/2020\/03\/24\/introduction-to-the-c11-feature-trailing-return-types?lang=en\u4e3a\u4e86\u8ba9\u51fd\u6570\u7684\u8fd4\u56de\u7c7b\u578b\u7684\u5199\u6cd5\u53ef\u4ee5\u66f4generalized\uff0c\u4e8e\u662fc++11\u652f\u6301\u4e86\u8fd4\u56de\u7c7b\u578b\u540e\u7f6e\u7684\u5199\u6cd5\u3002\u8fd9\u6837\u53ef\u4ee5\u7528\u53c2\u6570\u5217\u8868\u91cc\u7684\u53d8\u91cf\u7ed3\u5408decltype\uff0c\u6765\u58f0\u660e\u4e0d\u7528\u8fd4\u56de\u7c7b\u578b\u540e\u7f6e\u5c31\u65e0\u6cd5\u8868\u793a\u7684\u8fd4\u56de\u7c7b\u578b\u3002<\/a><\/p>\n\n\n\n<h1 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"initializer_list%E4%B8%8D%E8%83%BD%E8%A2%AB%E5%A4%8D%E5%88%B6\"><\/span><em>initializer_list<\/em>\u4e0d\u80fd\u88ab\u590d\u5236<span class=\"ez-toc-section-end\"><\/span><\/h1>\n\n\n\n<h1 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"%E4%B8%80%E4%BA%9B%E6%9C%89%E5%8A%A9%E4%BA%8E%E5%8F%91%E7%8E%B0%E4%BB%A3%E7%A0%81%E5%BC%82%E5%B8%B8%E7%9A%84%E7%BC%96%E8%AF%91%E9%80%89%E9%A1%B9\"><\/span>\u4e00\u4e9b\u6709\u52a9\u4e8e\u53d1\u73b0\u4ee3\u7801\u5f02\u5e38\u7684\u7f16\u8bd1\u9009\u9879<span class=\"ez-toc-section-end\"><\/span><\/h1>\n\n\n\n<p class=\"wp-block-paragraph\"><a href=\"https:\/\/clang.llvm.org\/docs\/DiagnosticsReference.html#woverloaded-virtual\">https:\/\/clang.llvm.org\/docs\/DiagnosticsReference.html#woverloaded-virtual<\/a><\/p>\n\n\n\n<h1 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"%E6%8A%91%E5%88%B6%E7%BC%96%E8%AF%91warning%E7%9A%84%E5%87%A0%E7%A7%8D%E6%96%B9%E5%BC%8F\"><\/span>\u6291\u5236\u7f16\u8bd1warning\u7684\u51e0\u79cd\u65b9\u5f0f<span class=\"ez-toc-section-end\"><\/span><\/h1>\n\n\n\n<p class=\"wp-block-paragraph\"><a href=\"https:\/\/nelkinda.com\/blog\/suppress-warnings-in-gcc-and-clang\/\">https:\/\/nelkinda.com\/blog\/suppress-warnings-in-gcc-and-clang\/<\/a><\/p>\n\n\n\n<h1 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"clang%E6%89%BE%E4%B8%8D%E5%88%B0%E5%A4%B4%E6%96%87%E4%BB%B6\"><\/span>clang\u627e\u4e0d\u5230\u5934\u6587\u4ef6<span class=\"ez-toc-section-end\"><\/span><\/h1>\n\n\n\n<p class=\"wp-block-paragraph\"><a href=\"https:\/\/www.berezovskyi.me\/2015\/02\/clang-fatal-error-headers-not-found\/\">https:\/\/www.berezovskyi.me\/2015\/02\/clang-fatal-error-headers-not-found\/<\/a><\/p>\n\n\n\n<h1 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"NULL%E4%B8%8Enullptr%E7%9A%84%E5%8C%BA%E5%88%AB\"><\/span>NULL\u4e0enullptr\u7684\u533a\u522b<span class=\"ez-toc-section-end\"><\/span><\/h1>\n\n\n\n<p class=\"wp-block-paragraph\"><a href=\"https:\/\/www.quora.com\/Whats-the-difference-between-NULL-and-nullptr-in-C++#:~:text=nullptr%20is%20a%20keyword%20that,zero%2C%20you%20should%20use%20nullptr%20.\">https:\/\/www.quora.com\/Whats-the-difference-between-NULL-and-nullptr-in-C++#:~:text=nullptr%20is%20a%20keyword%20that,zero%2C%20you%20should%20use%20nullptr%20.<\/a><\/p>\n\n\n\n<h1 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"placement_new\"><\/span>placement new<span class=\"ez-toc-section-end\"><\/span><\/h1>\n\n\n\n<p class=\"wp-block-paragraph\"><a href=\"https:\/\/www.geeksforgeeks.org\/placement-new-operator-cpp\/\">https:\/\/www.geeksforgeeks.org\/placement-new-operator-cpp\/<\/a><\/p>\n\n\n\n<h1 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Cannot_bind_packed_field\"><\/span>Cannot bind packed field<span class=\"ez-toc-section-end\"><\/span><\/h1>\n\n\n\n<p class=\"wp-block-paragraph\">https:\/\/gcc.gnu.org\/bugzilla\/show_bug.cgi?id=36566<br>\u5176\u5b9e\u53ef\u4ee5\u770b\u8fd9\u4e2astackoverflow\u4e0a\u7684\u95ee\u9898\uff1a<br>https:\/\/stackoverflow.com\/questions\/27491432\/why-cant-i-return-a-reference-to-a-packed-field<br>\u7b80\u5355\u8bf4\u5c31\u662f\u4e3a\u4ec0\u4e48\u4e0d\u80fd\u5bf9\u4e8e\u4f7f\u7528\u4e86packed\u6807\u8bb0\u7684class\/struct\uff0c\u4e0d\u80fd\u521b\u5efa\u5bf9\u8be5\u7c7b\u4e2d\u6210\u5458\u7684\u5f15\u7528\uff1f<br>\u539f\u56e0\u5728\u8be5\u95ee\u9898\u4e0b\u9762\u7684\u4e00\u4e2a\u56de\u7b54\u91cc\uff1a<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p>On architectures that aren&#8217;t byte addressable,the compiler still lets you access non-aligned fields by doing memory transforms behind the scenes (e.g. masking and shifting) to get your desired value. It only knows to do this because the struct is packed at compile time. If the compiler loses that packed information, then it may try to directly access a memory location that&#8217;s not supported and will hard fault. Even though in the OPs question it would make no difference, GCC plays it safe and disallows the operation.<\/p><\/blockquote>\n\n\n\n<p class=\"wp-block-paragraph\">\u5c31\u662f\u8bf4packed\u7684class\/struct\u91cc\u9762\u7684\u6210\u5458\u7684\u5730\u5740\u53ef\u80fd\u8fdd\u53cd\u4e86\u8be5\u6210\u5458\u7c7b\u578b\u7684\u5bf9\u9f50\u8981\u6c42\uff0c\u5f53\u6211\u4eec\u76f4\u63a5\u4f7f\u7528a.s\u8fd9\u79cd\u65b9\u5f0f\u6765\u8bfb\u5199\u7c7b\u4e2d\u7684\u6210\u5458\u65f6\uff0c\u7f16\u8bd1\u5668\u4ecd\u7136\u77e5\u9053\u8fd9\u662fpacked\u7c7b\u91cc\u9762\u7684\u6210\u5458\uff0c\u4f1a\u591a\u751f\u6210\u4e00\u4e9b\u4ee3\u7801\u5904\u7406\u6210\u5458\u5730\u5740\u6ca1\u6709\u5bf9\u9f50\u7684\u95ee\u9898\u3002\u4f46\u662f\u5f53\u6211\u4eec\u628a\u6210\u5458\u5730\u5740\u8d4b\u7ed9\u53e6\u5916\u7684\u6307\u9488\u6216\u8005\u5f15\u7528\u65f6\uff0c\u8fd9\u4e2a\u5730\u5740\u662fpacked\u7c7b\u91cc\u7684\u6210\u5458\u5730\u5740\u7684\u4fe1\u606f\u5c31\u88ab\u4e22\u6389\u4e86\uff0c\u7f16\u8bd1\u5668\u5728\u4f7f\u7528\u8fd9\u4e2a\u6307\u9488\u6216\u8005\u5f15\u7528\u65f6\u5c31\u4e0d\u4f1a\u6dfb\u52a0\u5730\u5740\u4e0d\u5bf9\u9f50\u7684\u4ee3\u7801\uff0c\u7a0b\u5e8f\u5c31\u53ef\u80fd\u51fa\u9519\u3002<\/p>\n\n\n\n<h1 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"%E9%9D%99%E6%80%81%E4%BB%A3%E7%A0%81%E6%A3%80%E6%9F%A5%E5%B7%A5%E5%85%B7\"><\/span>\u9759\u6001\u4ee3\u7801\u68c0\u67e5\u5de5\u5177<span class=\"ez-toc-section-end\"><\/span><\/h1>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"scan-build\"><\/span>scan-build<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"CodeChecker\"><\/span>CodeChecker<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>snap install --classic codechecker <\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">codechecker\u4f1a\u81ea\u52a8\u68c0\u6d4b<code>clang<\/code>\u547d\u4ee4\u7684\u5b58\u5728\uff0c\u4e3a\u4e86\u4f7f\u7528clang-10\u7684Cross Unit Translation\u7279\u6027\uff0c\u628a\u9ed8\u8ba4\u7684clang\u7ed9\u5378\u8f7d\u6389\uff0c\u5b89\u88c5clang-10\uff0c\u7136\u540e<a href=\"https:\/\/askubuntu.com\/questions\/791616\/set-clang-3-8-as-default\">\u628aclang-10\u8bbe\u7f6e\u4e3a\u9ed8\u8ba4\u7684clang<\/a>\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo update-alternatives --install \/usr\/bin\/clang++ clang++ \/usr\/bin\/clang++-10 100\nsudo update-alternatives --install \/usr\/bin\/clang clang \/usr\/bin\/clang-10 100<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">codechecker\u4f7f\u7528\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>codechecker check -b \"cd ~\/your-project &amp;&amp; make clean &amp;&amp; make\" -o .\/results <\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u5c06\u7ed3\u679c\u8f6c\u6362\u6210\u4e3ahtml\u6587\u4ef6\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>codechecker parse -e html .\/results -o .\/reports_html<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><a href=\"https:\/\/prereleases.llvm.org\/10.0.0\/rc3\/tools\/clang\/docs\/analyzer\/user-docs\/CrossTranslationUnit.html\">\u4f7f\u7528clang10\u7684ctu\u7279\u6027\u8fdb\u884c\u5206\u6790<\/a>\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>codechecker analyze --ctu compile_commands.json -o reports<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u8fd9\u4e2acompile_commands.json\u53ef\u7528\u4f7f\u7528\u4e0a\u4e00\u4e2acheck\u547d\u4ee4\u751f\u6210\u7684reports\u91cc\u751f\u6210\u7684json\u6587\u4ef6\u3002analyze\u7684\u7ed3\u679c\u4e5f\u53ef\u4ee5\u6309\u7167\u548ccheck\u4e00\u6837\u7684\u65b9\u5f0f\u8f6c\u6362\u4e3ahtml\u6587\u4ef6\u8fdb\u884c\u67e5\u770b\u3002<\/p>\n\n\n\n<h1 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"%E7%BC%96%E8%AF%91%E5%8F%82%E6%95%B0\"><\/span>\u7f16\u8bd1\u53c2\u6570<span class=\"ez-toc-section-end\"><\/span><\/h1>\n\n\n\n<p class=\"wp-block-paragraph\"><code>-shared<\/code>\u9690\u5f0f\u5305\u542b\u4e86<code>-fPIC<\/code>\uff0c\u4f46\u662f\u4e0d\u662f\u6240\u6709\u7684\u7cfb\u7edf\u90fd\u652f\u6301<code>-shared<\/code>\u9009\u9879\uff0c\u56e0\u6b64\u5f88\u591a\u65f6\u5019\u8fd8\u662f\u4f1a\u89c1\u5230\u8fd9\u4e24\u4e2a\u53c2\u6570\u4e00\u8d77\u7528\uff0e<\/p>\n","protected":false},"excerpt":{"rendered":"<p>ostringstream\u7684\u5f15\u7528\u4f5c\u4e3a\u51fd\u6570\u53c2\u6570\u7684\u5751\u60f3\u7740\u7528ostringstream\u7684\u5f15\u7528\u6765\u641e\u51e0\u4e2ajson\u7684\u5de5\u5177\u51fd\u6570\uff0c\u5c31\u50cf\u4e0b\u9762\u8fd9\u6837 \u4f1a\u62a5\u9519\uff1a error: no match for \u2018operator&#038;l&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[10],"tags":[8],"class_list":["post-194","post","type-post","status-publish","format-standard","hentry","category-10","tag-c"],"_links":{"self":[{"href":"https:\/\/blog.cauchyschwarz.com\/index.php?rest_route=\/wp\/v2\/posts\/194","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.cauchyschwarz.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.cauchyschwarz.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.cauchyschwarz.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.cauchyschwarz.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=194"}],"version-history":[{"count":1,"href":"https:\/\/blog.cauchyschwarz.com\/index.php?rest_route=\/wp\/v2\/posts\/194\/revisions"}],"predecessor-version":[{"id":195,"href":"https:\/\/blog.cauchyschwarz.com\/index.php?rest_route=\/wp\/v2\/posts\/194\/revisions\/195"}],"wp:attachment":[{"href":"https:\/\/blog.cauchyschwarz.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=194"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.cauchyschwarz.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=194"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.cauchyschwarz.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=194"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}