Hello,
Okay, since I am only experimenting with Visual C++ I should not be
extremely strict, but what I found will surprise many. I was _very_
surprised.
In case this bug is known (I couldn't find it reported, though), ignore my
report.
In case you find the code being in error - it is supposed to be 100%
Standard C++ - tell me and I'll take a break from C++.
I am using Visual C++ 2005 Express Edition.
First of all, here the code:
#include <iostream>
#include <ostream>
#include <utility>
int main()
{
typedef unsigned long bug_type;
bug_type a = 2;
bug_type b = 34;
bug_type c = 534;
bug_type d = std::max(std::max(a, b), c);
std::cout << "max value: " << d << "\n";
}
Create a new Win32 console project. I created mine without precompiled
headers and empty, but I don't think it matters (haven't tried it though).
Do not modify any project properties.
Add the code to the project, compile in Debug and Release mode. Output is as
expected.
Now set "project properties -> Configuration Properties -> C++ ->
Language -> Disable Language Extensions" to true.
Compile again in Debug and Release mode, also pay attention to warning
issued.
Now run both programs, and take a look at the output in debug mode and
release mode.
Now some properties of the bug:
1) It does not happen if some other type (e.g. int, long) is used as
bug_type.
2) It does not happen if there is only one std::max, e.g. the following
line:
bug_type d = std::max(a, b);
does not cause symptorms
3) It does not appear when language extensions are disabled (default)
4) It only appears in debug mode.
I find this really cool. Cool because such a simply bug, cool because it
took ages to track it down, cool because it vanishes in release mode.
If someone knows a prize for me, I will happily take one :-)
I will report it to the Microsoft page if people here agree that:
a) it is a bug, not my code being wrong
b) it is not reported
c) it can be reproduced on other machines
I wait with reporting because it looks so strange I believe I am dreaming.
Tell me if I am not.
Thomas