I am on Windows, I don't want to use WSL or Visual Studio. I want the compiler to tell me about stupid bugs. But I cannot figure out a way to do it.
The problem: I cannot figure out a way to catch both of the bugs below:
#include<iostream>
#include<vector>
#include<set>
using namespace std;
int main() {
//case 1
vector<int> V(5);
cout << V[10] << endl;
//case 2
set<int> Set;
cout << *Set.begin();
}
Using clang
Clang allows me to use sanitizers on windows. I was not able to find a way to make them work in mingw. Here are my flags:
I can successfully catch the case 1, in the error window I can clearly see what the mistake and the line where it happens.
But I get no errors when I have the case2 bug.
Using mingw
I found 2 useful blogs on codeforces on this topic. There I found about the -D_GLIBCXX_DEBUG flag, but it does not work for me with clang, so I used mingw.
Case1 is worse than in clang case, because I don't see the specific line
But the case2 is better than with clang, at least I know that something is wrong and what type of mistake I made, but sadly I don't see the specific line.
Both cases seem bad
I feel like I am doing something very wrong.
If you have a setup on windows that allows you to easily identify both of the bugs, I would be very interested to see how you did that.
I think this info can be useful to a lot of people who use windows and avoid using IDEs like visual studio (like people with low end pcs). I have seen too many people, including me, who manually search for this kind of bugs, and I think it should not be done like that.
try using -ggdb3 instead of -g in the second approach
Sadly it does not change the output for me. Also tried -g3 and got the same result
ok
.
Hello, did you manage to figure it out? I've been wondering how to do the same thing.