g++ does not complain when not returning form non-void

S

saneman

I have this function:

int getBeer(){
std::cout << "drunk\n";
}

when I compile with g++ I don't get any error or warning. Why?
 
V

Victor Bazarov

saneman said:
I have this function:

int getBeer(){
std::cout << "drunk\n";
}

when I compile with g++ I don't get any error or warning. Why?

Warnings are non-normative. Errors some are and some aren't. The
code as posted is *legal* (not ill-formed), although it does have
undefined behaviour if the function is called.

V
 
T

Thomas Tutone

I have this function:

int getBeer(){
std::cout << "drunk\n";

}

when I compile with g++ I don't get any error or warning. Why?

In addition to what Victor said, here's a platform-specific answer:

gcc does not turn on warnings by default. It is a good habit to
always compile your code with at least the following flags (assuming
your file is named "foo.cpp"):

g++ -Wall -Wextra -pedantic foo.cpp

That turns on many useful warnings. Some people add additional flags
to get more warnings. For additional info, consult the gcc manual, or
ask on a gcc-specific mailing list or forum.

Best regards,

Tom
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,135
Latest member
VeronaShap
Top