How to make warnings in visual studio

Suppose I have files a.cpp

and b.cpp

, and I get warnings in a.cpp

and an error in b.cpp

. I'm fixing the bug in b.cpp

and recompiling - since Visual Studio doesn't need to be recompiled a.cpp

, it doesn't remind me of the warnings that were encountered earlier.

I would like to somehow alert the warnings; however, I don't want it to treat warnings as errors (I would like it to still compile and execute even with warnings). Is it possible?

0


source to share


6 answers


Basically, you're out of luck. Compiling C ++ will throw away all errors and warnings. Since it will only recompile .CPP files that have a missing .OBJ file (i.e. those that had errors and crashed last time), you will only see errors.

You have several options. Off the top of my head:



  • Write a macro that responds to the build completion event. If he sees any warnings, he can delete the .OBJ file. CPP file will be compiled next time. Unfortunately, this means that your program might not work without recompilation.
  • You can write a macro that works differently: when starting the build, see if there are any warnings, then delete the .OBJ file.
  • Write a VS add that remembers warnings until the .CPP file is compiled again.
+1


source


You can go into project settings and set all warnings as errors in the C / C ++ tab (category: General).



+3


source


As Hernan said, add a custom build step that will make a copy of the intermediate file that contains the build results (warnings). Not sure how to do this, but you can create a bat file that is called as a custom build step.

Why do you want to keep the warnings outside of me. Treat them like bugs or ignore them or pragma / disable them.

+1


source


Rebuild the project or recompile just the a.cpp file. Warnings are printed by the compiler, so you won't get warnings for files not included in the current compilation.

You can save the current build output in the Output panel and press Ctrl + S (the default is output-build.txt if I remember well).

In your project settings, I think the prefab outputs can be saved to files. Check it out and report your results.

Greetings

0


source


Given that you don't want to recompile the files that cause the warning, one option you have is to write a small utility that filters the compiler output for the warnings and writes it to the .cpp file as // TODO.

The IDE will then put them in the task list.

I don't know of anything that does this out of the box, but it probably wouldn't be too hard to hack.

If you don't want the utility to delete the actual source files (and I'm not sure what I want), you might want them to write // TODO comments to a dummy todo.cpp file and have that file in your project. They will then appear in the task list, and since the file is nothing but comments, this will not affect the build. Just make sure the utility is smart to avoid adding duplicates to the list. It is possible to record a macro to jump from the todo.cpp line to the corresponding actual location of the alert.

0


source


I would highly recommend working with warnings for as many errors as possible and of course in all the code you write yourself. This is a way to fix the warnings here and now, and then wait until the end and try to do everything in one go.

There are several reasons why you want to run error warnings:

  • Most of the warnings actually indicate there is a problem with your code.
  • If you have a lot of warnings, you won't notice if a new one appears in the middle. I've seen this happen a lot.
  • If there is a warning that you think is bogus, or you simply cannot fix it right away for some reason, you can disable it. Use the / w option or a suitable #pragma. Note that you can only switch it for a specific file, or even at a specific location in your code. If you still want to be notified when compiling, but there is a #pragma message in there.
  • If there is code that is outside your control but you just need to compile it into your program, toggle warnings for that particular module or source file, or even run it without / WX. Chances are you are not changing the code anyway, so point 2 is probably not as relevant.

I really don't see any compelling reason not to work with / WX (or -Werror).

0


source







All Articles