Last active
August 29, 2015 14:24
-
-
Save tsaarni/5a2da9760e100245a259 to your computer and use it in GitHub Desktop.
Unintentional typecast that causes infinite recursive loop
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// clang++ -Wall -std=c++11 -O0 -o test test.cpp && ./test | |
// g++ -Wall -std=c++11 -O0 -o test test.cpp && ./test | |
#include <iostream> | |
#include <vector> | |
#include <cstdio> | |
namespace Ns | |
{ | |
struct Foo; | |
std::ostream& operator<<(std::ostream& os, const Foo& x) { return os; } | |
struct Foo | |
{ | |
// TO PREVENT accidental type conversion add "explicit" | |
// - for consideration: all non-explicit constructors with single parameter may trigger this problem | |
Foo(std::vector<int> i) | |
{ | |
printf("HEHEE\n"); | |
std::cout << i; | |
} | |
}; | |
} | |
int main(int, char*[]) | |
{ | |
Ns::Foo obj{{}}; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment