0
\$\begingroup\$

I'm getting an error that says "control may reach end of function" and I have gone through my code several times now and am not spotting the error. It may be something simple too.

// loop continually until the user gives a valid guess
FText GetValidGuess()
{
    EGuessStatus Status = EGuessStatus::Invalid_Status;
    do {
        // get a guess from the player
        int32 CurrentTry = BCGame.GetCurrentTry();
        std::cout << "Try " << CurrentTry << ". Enter your guess: ";
        FText Guess = "";
        std::getline(std::cin, Guess);

        // check status and give feedback
        Status = BCGame.CheckGuessValidity(Guess);
        switch (Status) {
            case EGuessStatus::Wrong_Length:
                std::cout << "Please enter a " << BCGame.GetHiddenWordLength() << " letter word.\n";
                break;
            case EGuessStatus::Not_an_isogram:
                std::cout << "Please enter a word witout repeating letters.\n";
                break;
            case EGuessStatus::Not_Lowercase:
                std::cout << "Please enter all lowercase letters.\n";
                break;
            default:
                return Guess;
        }
        std::cout << std::endl;
    } while (Status != EGuessStatus::OK); // keep looping until we get no error
}
\$\endgroup\$
2
  • 1
    \$\begingroup\$ In this case the compiler isn't smart enough to figure out that Status != EGuessStatus::OK is always true. So it assumes that it might be true or false - and if it's false, then the computer would get to the end of the function without returning anything. \$\endgroup\$ Commented May 4, 2016 at 22:35
  • \$\begingroup\$ @immibis - If that is correct, then that'd be better given as an answer than a comment. It doesn't have to be any different to your comment, but it allows the asker to accept it and thus mark this question as answered, and you'll gain some reputation for it, too. \$\endgroup\$ Commented May 5, 2016 at 3:47

1 Answer 1

1
\$\begingroup\$

The compiler isn't smart enough to figure out that Status != EGuessStatus::OK is always true.

So it assumes that it might be true or false - and if it's false, then the computer would get to the end of the function without returning anything, which is what that warning is trying to tell you.

One solution would be to change the condition to while(true).

\$\endgroup\$

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.