{"id":382780,"date":"2024-06-29T04:29:26","date_gmt":"2024-06-29T04:29:26","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=382780"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=382780","title":{"rendered":"<span>How we sympathize with a question on StackOverflow but keep silent<\/span>"},"content":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-1\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/post_images\/4c3\/3c0\/0f5\/4c33c00f5f7fdd1bf6cff4e021ee698f.png\" alt=\"How we sympathize with a question on StackOverflow but keep silent\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/4c3\/3c0\/0f5\/4c33c00f5f7fdd1bf6cff4e021ee698f.png\"\/><br \/>  On the stackoverflow.com website, we frequently see questions about how to look for bugs of a certain type. We know that PVS-Studio can solve the problem. Unfortunately, we have to keep silent. Otherwise, StackOverflow moderators may consider it as an obvious attempt to promote our product. This article describes a particular case of such a situation that makes us suffer deeply.<\/p>\n<p><a name=\"habracut\"><\/a>  <\/p>\n<p>The following question: &#171;<a href=\"https:\/\/stackoverflow.com\/questions\/69592513\/scan-build-for-clang-13-not-showing-errors\">Scan-Build for clang-13 not showing errors<\/a>&#187; asked by kratos from India, made me write this article. This person asks how to look for patterns of the following type:<\/p>\n<p>  <\/p>\n<ul>\n<li>writing integer values other than 0 and 1 to a bool type variable;<\/li>\n<li>virtual functions call in the constructor and destructor.<\/li>\n<\/ul>\n<p>  <\/p>\n<p>Here&#8217;s the code cited as an example:<\/p>\n<p>  <\/p>\n<pre><code class=\"cpp\">int f1(){ int a=5; short b=4; bool a1=a;\/\/maybe warn bool b1=b;\/\/maybe warn if(a1&amp;&amp;b1)return 1; return 0; } class M{ public:     virtual int GetAge(){return 0;} }; class P:public M{ public:     virtual int GetAge(){return 1;}     P(){GetAge();}\/\/maybe warn     ~P(){GetAge();}\/\/maybe warn };  int main(){     return 0; }<\/code><\/pre>\n<p>  <\/p>\n<p>To search for errors, kratos tried to use the Clang 13 compiler, but this isn&#8217;t working.<\/p>\n<p>  <\/p>\n<p>I don&#8217;t know whether you can find such errors with Clang or not \u2013 didn&#8217;t study this issue. Most likely, to find errors, you just have to specify the right flag for the compiler.<\/p>\n<p>  <\/p>\n<p>However, I am tempted to reply something as: try PVS-Studio. Although no \u2013 this is not enough to post an answer, but I was eager to add the comment as:<\/p>\n<p>  <\/p>\n<blockquote><p>I can&#8217;t tell you whether you can search for these errors with Clang, but the PVS-Studio static analyzer finds these errors right away: <a href=\"https:\/\/godbolt.org\/z\/Kx8hfx8en\">an example on the Compiler Explorer website<\/a>. Try it, maybe it&#8217;s gonna work \ud83d\ude42<\/p><\/blockquote>\n<p>The first suspicious pattern triggers the analyzer in two ways at once. Therefore, we have 4 warnings in total:<\/p>\n<p>  <\/p>\n<ul>\n<li>6:1: note: V547 The &#8216;A = a&#8217; expression is equivalent to the &#8216;A = true&#8217; expression.<\/li>\n<li>6:1: warning: V786 It is odd that value &#8216;a&#8217; is assigned to the &#8216;a1&#8217; variable. The value range of &#8216;a1&#8217; variable: [0, 1].<\/li>\n<li>7:1: note: V547 The &#8216;A = b&#8217; expression is equivalent to the &#8216;A = true&#8217; expression.<\/li>\n<li>7:1: warning: V786 It is odd that value &#8216;b&#8217; is assigned to the &#8216;b1&#8217; variable. The value range of &#8216;b1&#8217; variable: [0, 1].<\/li>\n<\/ul>\n<p>  <\/p>\n<p>And another two messages relating to the virtual functions call:<\/p>\n<p>  <\/p>\n<ul>\n<li>18:1: error: V1053 Calling the &#8216;GetAge&#8217; virtual function in the constructor may lead to unexpected result at runtime.<\/li>\n<li>19:1: error: V1053 Calling the &#8216;GetAge&#8217; virtual function in the destructor may lead to unexpected result at runtime.<\/li>\n<\/ul>\n<p>  <\/p>\n<p>Some programmers may find this information useful. Unfortunately, no one will know about this on StackOverflow :(.<\/p>\n<p>  <\/p>\n<p>First, the answer contains a commercial tool. Moreover, it&#8217;s <strong>the first question<\/strong> from kratos.<\/p>\n<p>  <\/p>\n<p><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/post_images\/76a\/b68\/2e2\/76ab682e2201416d74b47733984fb5f2.png\" alt=\"Moreover, it's the first question from kratos\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/76a\/b68\/2e2\/76ab682e2201416d74b47733984fb5f2.png\"\/><\/p>\n<p>  <\/p>\n<p>It may look as if I created a virtual user on purpose, asked a question, and answered it to promote PVS-Studio in a favorable light.<\/p>\n<p>  <\/p>\n<p>So, I can&#8217;t really post an answer. StackOverflow moderators may think that it&#8217;s a stupid spam trick and ban me :). Maybe we asked a question and answered it\u2026 At least we should have leveled up our virtual user asking the question\u2026 Not creative at all :).<\/p>\n<p>  <\/p>\n<p>Well, I didn&#8217;t reply to the question on StackOverflow, but I wrote this little note. Eventually, I feel relieved, and readers enjoy an unusual story from the life of the PVS-Studio team :).<\/p>\n<p>  <\/p>\n<p>Note. You may tartly say that such a comment promotes a proprietary tool. And StackOverflow must fine\/ban us for this. I don&#8217;t think so. For many developers, it won&#8217;t make any difference which tool to use. You can use PVS-Studio for free in various scenarios: &#171;<a href=\"https:\/\/habr.com\/en\/company\/pvs-studio\/blog\/443340\/\">Ways to Get a Free PVS-Studio License<\/a>&#171;.<\/p>\n<p>  <\/p>\n<p>Thanks for your attention. By the way, since we were talking about Clang, I invite you to take a look at a recent note &#171;<a href=\"https:\/\/habr.com\/en\/company\/pvs-studio\/blog\/582492\/\">Detecting errors in the LLVM release 13.0.0<\/a>&#171;. Wish you bugless code!<\/p>\n<\/div>\n<\/div>\n<\/div>\n<p><!----><!----><\/div>\n<p><!----><!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/articles\/585270\/\"> https:\/\/habr.com\/ru\/articles\/585270\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-1\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/post_images\/4c3\/3c0\/0f5\/4c33c00f5f7fdd1bf6cff4e021ee698f.png\" alt=\"How we sympathize with a question on StackOverflow but keep silent\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/4c3\/3c0\/0f5\/4c33c00f5f7fdd1bf6cff4e021ee698f.png\"\/><br \/>  On the stackoverflow.com website, we frequently see questions about how to look for bugs of a certain type. We know that PVS-Studio can solve the problem. Unfortunately, we have to keep silent. Otherwise, StackOverflow moderators may consider it as an obvious attempt to promote our product. This article describes a particular case of such a situation that makes us suffer deeply.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-382780","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/382780","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=382780"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/382780\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=382780"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=382780"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=382780"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}