Visual Studio 2010 build warning & errors

here are a couple of patches to address some warnings in Microsoft compilers, and a build error in vs2010 in particular

vs2010-errors.patch:
In SelectionDAGISel, std::pairs or pointers are being constructed using a 0 as an initializer causes an error inside the std::pair constructor. I think changes to language in support of the nullptr keyword caused this break.

vs2010-warnings.patch:
This patch fixes a couple of annoying warnings that show up all over the place because they are in headers. At least for Microsoft compilers, conversion of a int to bool requires the compiler to convert non-zero to one and so the compiler warns of the performance issue. My fix is to explicitly perform the conversion so the compiler knows I’m aware and doesn’t warn me. I don’t know the behavior of other compilers in this respect, so I don’t know if it should be committed. The other solution would be to change the return type of the accessors function to return ints, though this could move the warning elsewhere.

-Nathan

vs2010-errors.patch (1.73 KB)

vs2010-warnings.patch (1.03 KB)

here are a couple of patches to address some warnings
in Microsoft compilers, and a build error in vs2010 in particular
vs2010-errors.patch:
In SelectionDAGISel, std::pairs or pointers are being constructed using a 0
as an initializer causes an error inside the std::pair constructor. I think
changes to language in support of the nullptr keyword caused this break.

Yep, people keep doing this. I've been behind on the trunk for a bit,
but I was surprised to see this come up again. This is the correct
fix, but please make sure you stick within 80 cols.

vs2010-warnings.patch:
This patch fixes a couple of annoying warnings that show up all over the
place because they are in headers. At least for Microsoft compilers,
conversion of a int to bool requires the compiler to convert non-zero to one
and so the compiler warns of the performance issue. My fix is to explicitly
perform the conversion so the compiler knows I'm aware and doesn't warn me.
I don't know the behavior of other compilers in this respect, so I don't
know if it should be committed. The other solution would be to change the
return type of the accessors function to return ints, though this could move
the warning elsewhere.
-Nathan

This fix looks like a case of 3am programming. I think using
static_cast<bool> is clearer.

- Michael Spencer

here are updated versions

  • Nathan

vs2010-errors.patch (1.71 KB)

vs2010-warnings.patch (1.04 KB)

Nathan Jeffords <blunted2night@gmail.com> writes:

here are updated versions

Applied as 114662 and 114661. Thanks!

Note: static_cast doesn’t make the warning go away or did you check that? I just compiled a small test and it didn’t work. The recommended solution is:

(expression) != 0

http://msdn.microsoft.com/en-us/library/b6801kcy.aspx

It even says: Casting the expression to type bool will not disable the warning, which is by design.

Note: static_cast<bool> doesn't make the warning go away or did you check
that? I just compiled a small test and it didn't work. The recommended
solution is:

(expression) != 0

http://msdn.microsoft.com/en-us/library/b6801kcy.aspx

It even says: Casting the expression to type bool will not disable the
warning, which is by design.

I did not check that, sorry (I've not seen the warning). Thanks for
the proper fix :P.

- Michael Spencer

Sorry, I should have checked the change to the patch. Here is a new patch that fixes it. I found a couple of more places with the same issue.

-Nathan

vs-warnings.patch (1.83 KB)

Nathan Jeffords <blunted2night@gmail.com> writes:

Sorry, I should have checked the change to the patch. Here is a new patch
that fixes it. I found a couple of more places with the same issue.

Please submit a proper patch, not a file with a concatenation of
patches.

svn diff > my.patch

on the source root directory should do the trick.

Nathan Jeffords <blunted2night@gmail.com> writes:

I recreated the patch, it now has proper paths for the affected files.

Committed as r114796. Thanks!