Skip to content

Instantly share code, notes, and snippets.

@kaityo256
Created February 22, 2019 10:21
Show Gist options
  • Save kaityo256/641b5f9ec4dd771144031d636b299b75 to your computer and use it in GitHub Desktop.
Save kaityo256/641b5f9ec4dd771144031d636b299b75 to your computer and use it in GitHub Desktop.
Infinite Loop on Mac GCC
#include <iostream>
int foo(int m) {
std::cout << 1 << std::endl;
std::cout << 2 << std::endl;
}
void bar() {
foo(0);
}
int main() {
foo(0);
}
@kaityo256
Copy link
Author

$ g++ --version
g++ (Homebrew GCC 8.2.0) 8.2.0
Copyright (C) 2018 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

$ g++ -O1 test.cpp   
test.cpp: In function 'int foo(int)':
test.cpp:6:1: warning: no return statement in function returning non-void [-Wreturn-type]
 }
 ^

$ ./a.out
1
2
1
2
(snip)
zsh: segmentation fault  ./a.out

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment