Wandoka's blog

By Wandoka, 5 months ago, In English

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:

clang 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.

error message case1

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.

mingw flags

Case1 is worse than in clang case, because I don't see the specific line

error message case1

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.

error message case2

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.

compiler info clang
compiler info g++
  • Vote: I like it
  • +32
  • Vote: I do not like it

»
5 months ago, # |
  Vote: I like it 0 Vote: I do not like it

try using -ggdb3 instead of -g in the second approach

  • »
    »
    5 months ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    Sadly it does not change the output for me. Also tried -g3 and got the same result

»
5 months ago, # |
  Vote: I like it 0 Vote: I do not like it

ok

»
5 months ago, # |
  Vote: I like it 0 Vote: I do not like it

.

»
2 months ago, # |
  Vote: I like it 0 Vote: I do not like it

Hello, did you manage to figure it out? I've been wondering how to do the same thing.