You need to increase the warning level that you are using. foo; - a valid expression operator (the name of the function is converted to a pointer to a named function), but it has no effect.
I usually use -std=c++98 -Wall -Wextra -pedantic , which gives:
<stdin>: In function 'void foo()': <stdin>:2: error: 'cout' was not declared in this scope <stdin>: In function 'int main()': <stdin>:6: warning: statement is a reference, not call, to function 'foo' <stdin>:6: warning: statement has no effect
Charles Bailey
source share