0

It is immeasurably useful to be able to compile a file (Ctrl + F7) to quickly check if I have written code that compiles. I am finding that with my current settings function code will not be compiled unless specifically called elsewhere, leaving me with untested code until I later hook it up.

I recognize that this is a useful optimization for actually building it (especially in release), but it is a setting I would like to disable to allow quick compile-testing without having to explicitly call my new function somewhere in code.

Where is this setting in Visual Studio 2019?

  • Right now, by default, VS does exactly this. Are you actually working with function _templates_, not just functions? If so you will need to at least instantiate the templates with whatever types you want to check compile correctly. – Nathan Pierson Nov 06 '21 at 23:10
  • This is expected behaviour with templates. The standard allows templated code to be compiled/diagnosed without instantiating (i.e. using) the templates and further diagnosis is performed (e.g. later in a source file) on actually instantiating the templates. This allows source files to include standard library headers and third-party header-only libraries with templates, without instantiating every template. If you want to do "quick compile-testing" write a source file to instantiate templates you need to test (e.g. call templated functions with concrete arguments). – Peter Nov 07 '21 at 03:05
  • *"I recognize that this is a useful optimization for actually building it"* -- no, it's not. Once projects get above trivial size, they tend to (should) be split across several files. The compiler processes one file at a time, so it has no way of knowing which functions are called from other files. The compiler must compile every **non-`inline`** function in case it is called from a different file. The optimization that is useful occurs in the linking phase, when functions can be dropped if not used. *Whether or not a function has an inline definition is an important detail for this question.* – JaMiT Nov 07 '21 at 03:47
  • Ah! I am working with function templates. Thank you for the info! @JaMiT right you are; I had forgotten that occurred during linking. – Paul Dziadzio Nov 08 '21 at 03:21
  • Since you've confirmed we're dealing with templates, it looks like this falls under [How do I force a particular instance of a C++ template to instantiate?](https://stackoverflow.com/questions/2152002/) Explicitly instantiating a version of each template should give you what you want. – JaMiT Nov 08 '21 at 03:34

0 Answers0