{"id":6505,"date":"2024-11-03T18:41:49","date_gmt":"2024-11-04T02:41:49","guid":{"rendered":"https:\/\/visualgdb.com\/w\/?p=6505"},"modified":"2024-11-04T19:30:13","modified_gmt":"2024-11-05T03:30:13","slug":"using-static-code-analyzers-with-visualgdb","status":"publish","type":"post","link":"https:\/\/visualgdb.com\/documentation\/intellisense\/analyzers\/","title":{"rendered":"Using Static Code Analyzers with VisualGDB"},"content":{"rendered":"<p>You can use the Advanced Clang IntelliSense engine included with VisualGDB to automatically check your code for common errors.<\/p>\n<p>Once static code analysis is enabled, VisualGDB automatically run the <a href=\"https:\/\/clang.llvm.org\/docs\/ClangStaticAnalyzer.html\">Clang Static Analyzers<\/a> on the source files you edit and will display the analysis messages in the Errors window.<\/p>\n<p>You can configure the enabled analyzers via <strong>VisualGDB Project Properties -&gt; Code Analyzers<\/strong>:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2020\/07\/01-setting-2.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-8898\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2020\/07\/01-setting-2.png\" alt=\"\" width=\"1409\" height=\"738\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2020\/07\/01-setting-2.png 1409w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2020\/07\/01-setting-2-300x157.png 300w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2020\/07\/01-setting-2-1024x536.png 1024w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2020\/07\/01-setting-2-768x402.png 768w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2020\/07\/01-setting-2-390x205.png 390w\" sizes=\"(max-width: 1409px) 100vw, 1409px\" \/><\/a>The messages from the analyzers for the current file will appear in the <strong>Error List<\/strong> window together with the regular errors and warnings: <a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2020\/07\/02-result.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-8896\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2020\/07\/02-result.png\" alt=\"\" width=\"1203\" height=\"629\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2020\/07\/02-result.png 1203w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2020\/07\/02-result-300x157.png 300w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2020\/07\/02-result-1024x535.png 1024w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2020\/07\/02-result-768x402.png 768w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2020\/07\/02-result-390x205.png 390w\" sizes=\"(max-width: 1203px) 100vw, 1203px\" \/><\/a>You can quickly check if the analyzers are working with the following code example:<\/p>\n<pre class=\"\">#include &lt;stdlib.h&gt;\r\n\r\nvoid LeakDemo()\r\n{\r\n    int *p = (int *)malloc(123);\r\n    if (rand() == 42)\r\n        return;\r\n}<\/pre>\n<p>If the messages from the code analyzers do not appear, make sure the currently edited file is handled by the Clang IntelliSense engine by checking the buttons in the upper right corner:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2020\/07\/sense.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-6508\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2020\/07\/sense.png\" alt=\"\" width=\"843\" height=\"76\" \/><\/a><\/p>\n<p>If not, see our <a href=\"https:\/\/visualgdb.com\/documentation\/intellisense\/\">IntelliSense documentation<\/a> for instructions on enabling Clang IntelliSense.<\/p>\n<p>Also, enabling some experimental analyzers (<strong>alpha.*<\/strong>) may stop the analyzers from working due to missing option:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2024\/11\/04-err.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-8901\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2024\/11\/04-err.png\" alt=\"\" width=\"845\" height=\"244\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2024\/11\/04-err.png 845w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2024\/11\/04-err-300x87.png 300w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2024\/11\/04-err-768x222.png 768w\" sizes=\"(max-width: 845px) 100vw, 845px\" \/><\/a><\/p>\n<p>This can be fixed by adding the following option to the <strong>additional arguments<\/strong> field:<\/p>\n<pre>\r\n-analyzer-config aggressive-binary-operation-simplification=true<\/pre>\n<p><a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2020\/07\/03-option.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-8899\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2020\/07\/03-option.png\" alt=\"\" width=\"1013\" height=\"407\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2020\/07\/03-option.png 1013w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2020\/07\/03-option-300x121.png 300w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2020\/07\/03-option-768x309.png 768w\" sizes=\"(max-width: 1013px) 100vw, 1013px\" \/><\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>You can use the Advanced Clang IntelliSense engine included with VisualGDB to automatically check your code for common errors. Once<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[199],"tags":[],"_links":{"self":[{"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/posts\/6505"}],"collection":[{"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/comments?post=6505"}],"version-history":[{"count":5,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/posts\/6505\/revisions"}],"predecessor-version":[{"id":8903,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/posts\/6505\/revisions\/8903"}],"wp:attachment":[{"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/media?parent=6505"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/categories?post=6505"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/tags?post=6505"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}