{"id":22255,"date":"2019-01-24T10:01:54","date_gmt":"2019-01-24T18:01:54","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/vcblog\/?p=22255"},"modified":"2019-04-10T22:15:49","modified_gmt":"2019-04-10T22:15:49","slug":"c-productivity-improvements-in-visual-studio-2019-preview-2","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/cppblog\/c-productivity-improvements-in-visual-studio-2019-preview-2\/","title":{"rendered":"C++ Productivity Improvements in Visual Studio 2019 Preview 2"},"content":{"rendered":"<p>Visual Studio 2019 Preview 2 contains a host of productivity features, including some new quick fixes and code navigation improvements:<\/p>\n<ul>\n<li>Quick fixes for:\n<ul>\n<li><a href=\"#AddMissingInclude\">Add missing #include<\/a><\/li>\n<li><a href=\"#NULLtonullptr\">NULL to nullptr<\/a><\/li>\n<li><a href=\"#AddMissingSemicolon\">Add missing semicolon<\/a><\/li>\n<li><a href=\"#ResolveMissingNamespace\">Resolve missing namespace or scope<\/a><\/li>\n<li><a href=\"#ReplaceIndirectionOperand\">Replace bad indirection operands (* to &amp; and &amp; to *)<\/a><\/li>\n<\/ul>\n<\/li>\n<li><a href=\"#QuickInfoClosingBrace\">Quick Info on closing brace<\/a><\/li>\n<li><a href=\"#PeekHeaderCode\">Peek Header \/ Code File<\/a><\/li>\n<li><a href=\"#GoToDocumentInclude\">Go to Document on #include<\/a><\/li>\n<\/ul>\n<p>The Quick Actions menu can be used to select the quick fixes referenced below. You can hover over a squiggle and click the lightbulb that appears or open the menu with <em>Alt + Enter<\/em>.<\/p>\n<h3><a id=\"AddMissingInclude\"><\/a>Quick Fix: Add missing #include<\/h3>\n<p>Have you ever forgotten which header to reference from the C++ Standard Library to use a particular function or symbol? Now, Visual Studio will figure that out for you and offer to fix it:\n<a href=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2019\/01\/addinclude1.gif\"><img decoding=\"async\" class=\"aligncenter size-full wp-image-22425\" src=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2019\/01\/addinclude1.gif\" alt=\"When you use a type or function defined in a different header, and that header was not #included in the file, Visual Studio squiggles the symbol in red. Now, when you hover over the squiggle, you will be shown an option to automatially add the missing #include. \" width=\"654\" height=\"247\" \/><\/a><\/p>\n<p>But this feature doesn\u2019t just find standard library headers. It can tell you about missing headers from your codebase too:\n<a href=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2019\/01\/add-include-nonstl1.gif\"><img decoding=\"async\" class=\"aligncenter size-full wp-image-22435\" src=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2019\/01\/add-include-nonstl1.gif\" alt=\"The add missing #include quick fix even works for non-STL headers included in your codebase, so you don't have to remember where you declared everything all the time.\" width=\"920\" height=\"298\" \/><\/a><\/p>\n<h3><a id=\"NULLtonullptr\"><\/a>Quick Fix: NULL to nullptr<\/h3>\n<p>An automatic quick fix for the NULL-&gt;nullptr code analysis warning (<a href=\"https:\/\/docs.microsoft.com\/en-us\/visualstudio\/code-quality\/c26477\" target=\"_blank\" rel=\"noopener\">C26477: USE_NULLPTR_NOT_CONSTANT<\/a>) is available via the lightbulb menu on relevant lines, enabled by default in the \u201cC++ Core Check Type Rules,\u201d \u201cC++ Core Check Rules,\u201d and \u201cMicrosoft All Rules\u201d rulesets. To change rulesets in a MSBuild project, navigate to Property Pages > Code Analysis > General; for projects using CMake, add the <code>\"codeAnalysisRuleset\"<\/code> key into your CMakeSettings.json with the value set to the full path or the filename of a ruleset file.\n<a href=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2019\/01\/null-to-nullptr1.gif\"><img decoding=\"async\" class=\"aligncenter size-full wp-image-22445\" src=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2019\/01\/null-to-nullptr1.gif\" alt=\"It is generally bad practice to use the &quot;NULL&quot; macro in modern C++ code, so Visual Studio will place a squiggle under NULLs. When you hover over such a squiggle, Visual Studio will over to replace it with a nullptr for you. \" width=\"874\" height=\"341\" \/><\/a>\nYou\u2019ll be able to see a preview of the change for the fix and can choose to confirm it if it looks good. The code will be fixed automatically and green squiggle removed.<\/p>\n<h3><a id=\"AddMissingSemicolon\"><\/a>Quick Fix: Add missing semicolon<\/h3>\n<p>A common pitfall for students learning C++ is remembering to add the semicolon at the end of a statement. Visual Studio will now identify this issue and offer to fix it.\n<a href=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2019\/01\/addsemicolon1.gif\"><img decoding=\"async\" class=\"aligncenter size-full wp-image-22455\" src=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2019\/01\/addsemicolon1.gif\" alt=\"Visual Studio offers to add missing semicolons to your code where needed. Just hover over the squiggle that appears and choose the option to fix it in the menu. \" width=\"1250\" height=\"401\" \/><\/a><\/p>\n<h3><a id=\"ResolveMissingNamespace\"><\/a>Quick Fix: Resolve missing namespace or scope<\/h3>\n<p>Visual Studio will offer to add a \u201cusing namespace\u201d statement to your code if one is missing, or alternatively, offer to qualify the symbol\u2019s scope directly with the scope operator:\n<a href=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2019\/01\/add-std1.gif\"><img decoding=\"async\" class=\"aligncenter size-full wp-image-22465\" src=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2019\/01\/add-std1.gif\" alt=\"When you forget to qualify a type or function with the namespace it comes from, Visual Studio will offer to fill in the missing namespace, along with the scope operator, in the code. Alternatively, you can let Visual Studio insert a &quot;using namespace&quot; statement above the code. \" width=\"624\" height=\"296\" \/><\/a>\nNote: we are currently tracking a bug with the quick fix to add &#8220;using namespace&#8221; that may cause it to not work correctly &#8211; we expect to resolve it in a future update.<\/p>\n<h3><a id=\"ReplaceIndirectionOperand\"><\/a>Quick Fix: Replace bad indirection operands (* to &amp; and &amp; to *)<\/h3>\n<p>Did you ever forget to dereference a pointer and manage to reference it directly instead? Or perhaps you meant to refer to the pointer and not what it points to? This quick action offers to fix such issues:\n<a href=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2019\/01\/replace-bad-indirection-operands1.gif\"><img decoding=\"async\" class=\"aligncenter size-full wp-image-22475\" src=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2019\/01\/replace-bad-indirection-operands1.gif\" alt=\"Visual Studio will offer to correct errors arising from using a * insteaof a &amp; in your code (and vice versa). Hover over the squiggle and choose the corresponding fix to resolve the issue. \" width=\"539\" height=\"260\" \/><\/a><\/p>\n<h3><a id=\"QuickInfoClosingBrace\"><\/a>Quick Info on closing brace<\/h3>\n<p>You can now see a Quick Info tooltip when you hover over a closing brace, giving you some information about the starting line of the code block.\n<a href=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2019\/01\/qi-on-closing-brace-v21.png\"><img decoding=\"async\" class=\"aligncenter size-full wp-image-22485\" src=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2019\/01\/qi-on-closing-brace-v21.png\" alt=\"When you hover over a closing brace in Visual Studio, context will be provided about the starting line of the code block. \" width=\"492\" height=\"119\" \/><\/a><\/p>\n<h3><a id=\"PeekHeaderCode\"><\/a>Peek Header \/ Code File<\/h3>\n<p>Visual Studio already had a feature to toggle between a header and a source C++ file, commonly invoked via <em>Ctrl + K, Ctrl + O<\/em>, or the right-click context menu in the editor. Now, you can also peek at the other file without leaving your current one with Peek Header \/ Code File (<em>Ctrl + K, Ctrl + J<\/em>):\n<a href=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2019\/01\/peek-header-code1.gif\"><img decoding=\"async\" class=\"aligncenter size-full wp-image-22495\" src=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2019\/01\/peek-header-code1.gif\" alt=\"You can peek at the header of a C++ source file with Ctrl + K, Ctrl + J. You can also peek at the source file of a header the same way. \" width=\"1335\" height=\"298\" \/><\/a><\/p>\n<h3><a id=\"GoToDocumentInclude\"><\/a>Go to Document on #include<\/h3>\n<p>F12 is often used to go to the definition of a code symbol. Now you can also do it on #include directives to open the corresponding file. In the right-click context menu, this is referred to as <strong>Go to Document<\/strong>:\n<a href=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2019\/01\/go-to-document1.gif\"><img decoding=\"async\" class=\"aligncenter size-full wp-image-22505\" src=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2019\/01\/go-to-document1.gif\" alt=\"You can now press F12 on a #include directive to go to that file in Visual Studio.\" width=\"1513\" height=\"627\" \/><\/a><\/p>\n<h3>Other productivity features to check out<\/h3>\n<p>We have several more C++ productivity improvements in Preview 2, covered in separate blog posts:<\/p>\n<ul>\n<li><a href=\"https:\/\/blogs.msdn.microsoft.com\/vcblog\/2019\/01\/24\/template-intellisense-improvements-for-visual-studio-2019-preview-2\/\" target=\"_blank\" rel=\"noopener\">Template IntelliSense Improvements<\/a><\/li>\n<li><a href=\"https:\/\/blogs.msdn.microsoft.com\/vcblog\/2019\/01\/24\/in-editor-code-analysis-in-visual-studio-2019-preview-2\/\" target=\"_blank\" rel=\"noopener\">In-editor Code Analysis<\/a><\/li>\n<li><a href=\"https:\/\/blogs.msdn.microsoft.com\/vcblog\/2019\/01\/24\/introducing-the-new-cmake-project-settings-ui\/\" target=\"_blank\" rel=\"noopener\">Introducing the New CMake Project Settings UI<\/a><\/li>\n<li>Code analysis new rules: Concurrency, coroutines &amp; move after free, and <a href=\"https:\/\/devblogs.microsoft.com\/cppblog\/lifetime-profile-update-in-visual-studio-2019-preview-2\/\" target=\"_blank\" rel=\"noopener\">Lifetime Profile update<\/a><\/li>\n<\/ul>\n<h3>We want your feedback<\/h3>\n<p>We\u2019d love for you to <a href=\"https:\/\/visualstudio.microsoft.com\/vs\/preview\/\" target=\"_blank\" rel=\"noopener\">download Visual Studio 2019<\/a> and give it a try. As always, we welcome your feedback. We can be reached via the comments below or via email (<a href=\"mailto:visualcpp@microsoft.com\" target=\"_blank\" rel=\"noopener\">visualcpp@microsoft.com<\/a>). If you encounter problems with Visual Studio or MSVC, or have a suggestion for us, please let us know through <strong>Help &gt; Send Feedback &gt; Report A Problem \/ Provide a Suggestion <\/strong>in the product, or via <a href=\"https:\/\/developercommunity.visualstudio.com\/spaces\/8\/index.html\" target=\"_blank\" rel=\"noopener\">Developer Community<\/a>. You can also find us on Twitter (<a href=\"https:\/\/twitter.com\/visualc\" target=\"_blank\" rel=\"noopener\">@VisualC<\/a>) and Facebook (<a href=\"https:\/\/www.facebook.com\/msftvisualcpp\" target=\"_blank\" rel=\"noopener\">msftvisualcpp<\/a>).<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Visual Studio 2019 Preview 2 contains a host of productivity features, including some new quick fixes and code navigation improvements: Quick fixes for: Add missing #include NULL to nullptr Add missing semicolon Resolve missing namespace or scope Replace bad indirection operands (* to &amp; and &amp; to *) Quick Info on closing brace Peek Header [&hellip;]<\/p>\n","protected":false},"author":1063,"featured_media":22761,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[270],"tags":[],"class_list":["post-22255","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-announcement"],"acf":[],"blog_post_summary":"<p>Visual Studio 2019 Preview 2 contains a host of productivity features, including some new quick fixes and code navigation improvements: Quick fixes for: Add missing #include NULL to nullptr Add missing semicolon Resolve missing namespace or scope Replace bad indirection operands (* to &amp; and &amp; to *) Quick Info on closing brace Peek Header [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/posts\/22255","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/users\/1063"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/comments?post=22255"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/posts\/22255\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/media\/22761"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/media?parent=22255"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/categories?post=22255"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/tags?post=22255"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}