hey guys your boy Chile here welcome back to C plus plus game engine infrastructure today we are gonna be super charging our project with a little static analysis now before I jump into that take a look at this code here I've had a little bit of test code and this test code exemplifies a mistake that I just I just can't help myself I continually make this mistake and every time I catch myself I'm like I should know better but at the same time I know I'm gonna do this again luckily uh I mean you would at some point I I asked myself why doesn't the compiler warn me about this because this is really dumb and annoying and I just want my compiler to tell me when I'm being dumb and annoying and after looking into it I found out that there is a way to get the compiler to tell you what you're doing wrong in this situation right now you can see here you know there's no warnings let me just do a rebuild solution there's no warnings um but you know those of you who are keen and C plus plus pilled will very quickly probably you know see what problem I am alluding to here so let's see if we can make our our tool set here help us out to help me out to stop being so dumb sometimes so we're gonna go into our property Pages because we want to make sure that this applies to everything we do in all of our projects and we're going to go down to code analysis and what we're gonna do here is uh we are gonna go to Microsoft so we have a whole set of rules here and we start off by default in the Microsoft native recommended rules but we're going to configure this and now we're gonna customize it because it does not enable by default the ones that I wish to be enabled so we can I mean there's two big sections here one of them is managed binary analysis and I don't think any of that really applies I think that might be CLR stuff but I'm not exactly sure but at any rate none of them are set but here here's the ones that do kind of matter for us native code and there's a lot of them and I don't want to read them all but I know what I'm looking for so we can just kind of filter that with a term so the one I'm looking for is I think it probably would be under I think it would be under D structure so we need virtual Destructor this is very important um now there's another rule here that we can kind of add while we're at it override so override explicitly good and don't override Destructor explicitly so let's add these two this one kind of important in my opinion this one really only a style issue but we might as well add it in here all right so we can see here it says this is a Microsoft rule set and cannot be modified well I just modified it any changes will be saved to a copy okay so press Ctrl s to save and yes it comes up with this little thing here let's go to the root of our solution and let's just call this uh Baseline and this will be Baseline dot rule set all right so now it should be all good right now if I run this I should get an error like I make no okay well maybe I'll just rebuild solution and we'll get the warning no warning okay well thank you thank you for that um we'll go back to the properties we'll see that it is Microsoft native recommended rules that's not right that's just the one we had before but I changed it it should be copy of Microsoft native recommended roles and here we see a problem right away when we save it as another file the name of the rule set is copy of you know base rule set that you started with but you know I have many projects I will have many that have this name it's kind of annoying if I select this one uh let me check a different one okay yeah all right so let's check this one yeah they all look about the same but we notice here that it gives you the path to the file and this one is not the path to our project so this is the one we just saved so this is the one that we want apply that okay all right so now we should have our static analysis and actually you might have noticed those squigglies popped up here telling us hey you got a virtual function on this class here you should probably add a virtual Destructor because if you inherit from this class uh it's not going to be a good time without that virtual Destructor good advice and this one says that plus also you should probably you know explicitly override this stuff so that's good and if we build it we'll also see that it says no warnings at all everything's fine wait a minute that's not right okay go back to properties we'll get there we're getting there we should enable code analysis on build so that that stuff catches our eye wow we're building let's rebuild what do we see all right so now we see our warnings in our build and we see our warnings in our intellisense and the they just went away but now they're back again um beautiful so what do we do next well before we fix these let me show you just something a little interesting here um little options for configuring our a rule set so go back to Microsoft It Go configure yes here we are so if we right click here we can show the properties of the rule set and we see here is where that name comes in copy of Microsoft native recommended rules so we can change this to I don't know chill engine Baseline C plus plus rules there you go uh uh and we could change the description as well if we wanted to change it to oh Doyle only 90s kids and then we save it and now if I were let me just close this I don't need that anymore well we probably do need it actually now that I think about it but we'll get back there so now we can see here in our list here it has a real name it's not just copy of Microsoft uh and the description is oh Doyle and everyone is happy let's go back to configure here let me show you one more thing so we can go through here we can here's all the different rules a lot of these correspond to things in the C plus plus core guidelines so if you're familiar with those you can enable ones that resonate with you uh um and again you can filter but another thing you can do is you can add or remove child rule sets so you have this list of rule sets and you can say uh yeah give me you know all of the ones from this wheel set and it'll merge them into your custom rule set so give me all you know the the C plus plus core guidelines STL rules and it'll merge those all in we're not going to do that right now but we could if we wanted to that's what I want that's what I wanted to say basically all right so now let's fix our problems problem the first we need to say that our Destructor is virtual so we'll just kind of default that bad boy if I save this now if we wait a little bit Yeah the intellisense will catch up and it will not complain anymore we still got one problem here easily addressed with the override override there we go and that should make this go away that should make this go away let me save the file that should make this there we go and then we rebuild the solution and we should get zero warnings Bob is your uncle beautiful all done so like I said there's lots of rules you add the ones that you know you come across as you come across them I think you can build up your own custom rule set or you could Google I don't know online other people's recommended rule sets I don't know man you do you um now one little thing that you might get caught up on here I don't want to come up with an example here but it's going to come up probably in a future video but if you include something uh like windows. h a lot of stuff in here is not going to uh live in peaceful coexistence with a lot of the rules in your static analysis because windows. h is kind of Jank and so that's going to throw a whole bunch of garbage into your build output but you can't just really go and muck around changing stuff in the windows headers so what you can do I mean you always have the option to just give up on the rule if you don't think it's going to add that much to your life but if you really want to keep the rule and you really want to include Windows what you can do is you can wrap the windows include with some of this pragma where you can first of all you save the current state of the warning system then you can disable the ones that are causing problems you include windows and then you pop to restore the previous state of all of the warning uh enablements if you will now of course that would be weird to do everywhere you include windows.
h which is why you would have a separate header maybe you'd call it something like chillwin. h and in that header you would you know you would set the defines that customize Windows you would set your warning pragmas then you include windows and you reset and instead of including windows. h everywhere you would include chillwin.
h you're familiar with this concept probably if you've ever seen my Hardware 3D Series so we never include the raw Windows header in that case we would include our wrapper header that does a bunch of stuff that makes life beautiful okay so this is something that we'll probably have to do in the future but we won't be doing it today one thing I just want to draw your attention to I haven't is that we set the static analysis settings in our Baseline uh property sheet so automatically it applies to all the stuff in our uh all of our projects all of our flavors of build they all get this in one shot beautiful in any future projects that we add we are going to attach the Baseline property sheet and they will also get these settings just a just a wonderful time and one of the Beauties about uh these rule sets here our custom rule sets they live in the file here called baseline.