Error in Xcode

Hello Forum,

Working through the lecture on switch statements in Xcode, I’ve encountered an error that doesn’t seem to manifest in Ben’s Visual Studio. This error is pictured below.

A quick google suggests that this error sometimes will appear in Xcode even if that same code is identical to that which runs uninterrupted inside of Visual Studio.

Does anyone know how I can fix this error? What return value might I need to add to my code so that the build will succeed again.

Thanks in advance for any assistance you fine folks can provide.

Hello Flynn.

return Guess;

?

You are looping till guess is OK, so the function will never return anything invalid.
You can additionally edit the:

default: return Guess;

and make it a

default: break;

But in this case put the definition&decalarion of “FText Guess…” before the do…while-loop.

Hope that helps.

Chris

Hi Phrobion,

Thanks for the advice. Unfortunately, after finishing the next video and doing as you and Ben described, I still have the same error.

And suggestions into how I might fix this would be greatly appreciated. Maybe @sampattuzzi would know as this might be Mac-specific?

Thank you.

Thats saying that the control might reach the end of the function without reaching a return statement. You can just ignore it because the logic of the function shouldn’t allow that to happen.

Hello @Flynn_Ringrose.

For me this code looks totally ok.

On this page http://en.cppreference.com/w/cpp/language/switch is said that “many compilers issue warnings if one of the enumerators is not handled”

So maybe you need to add a line:

case EGuessStatus::OK :

EDIT: I had to put a space between ok and the colon,
cause the forum-view makes an emoji … ::ok:

(without a “break;” above the "default: line).

Hope that helps. Your code looks fine for me.

Chris

Hey guys,

Thanks a lot for the advice. I’ll try what @phrobion described when I’m home tonight. Presently however, I can’t ignore this error as my build fails when I try to run it. As it stands, I can’t test my game as @ben is instructing in the lectures. :worried:

I’ll post back whether I have any success with your suggestions.

Thank you.

Hey guys,

I did as @phrobion described but to no avail. However, after erasing and rewriting identical code to that pictured originally above, the error did not reappear. Perhaps there was some sort of hidden data supplied by autofill? In any case I’m glad it’s working now.

Thanks for all your help.

So glad it’s working for you now.

I’m having the exact same problem in the same place using Xcode, I’ve tried what you said and re-written the code without using the autofill, but I’m still getting the same issue.

You need return Guess; after the while loop too.

}(while Status != EGuessWordStatus::OK);
return Guess;
1 Like

Hello Forum,

i am encountering the exact same issue as Flynn was in Xcode except when he re-wrote the code without auto complete it fixed the issue, i on the other hand have re-wrote the code twice and still i am getting the error. I even deleted my code and copy and pasted bens exact code to make sure it wasn’t me missing something. any help would be greatly appreciated because as of now i am completely stuck

thanks in advance

Hey,

In the video Ben mentions that Visual Studio (VS) will generate a warning that not all code paths will return a value. In Xcode I encountered the exact same problem as you are having and I suppose it is probably down to how strict the compiler is set to be in VS and Xcode. In order to solve the issue myself I rewrote the code so that all code paths do indeed return a value.

A link to said code that compiles fine for me can be found here.

The first step is to extract the FString guess outside of the scope of the while loop.
The second step is to change the default behaviour of the switch statement to set the condition to Ok, so that the while loop will break when no errors are found.
The third step is to put the return statement in the main scope of the GetValidGuess function, this means that at some point the function will always hit this return value.

I hope this helps!

I ran into the same problem running Xcode version 8.3.2 on macOS Sierra 10.12.5.

The solution that worked for me was return 0; after my do/while loop. This exits the function with a ‘Succeed’ value.

A non-void function doesn’t return anything. However, FText is synonymous of std::string. Therefore, we need to return something.

Here’s a screenshot of my function in iTerm2.

This also means you need to move your declaration of ‘Guess’ outside the do loop.

Which it was.

Good point, my apologies. It was also of course dealt with in the next lesson… Too keen to follow the exhortations of our lecturers to engage on here.

I have this error as well. I fixed it with added a return empty string before the closing brace.
I am running osx Sierra (10.12.4 (16E195)) Xcode (Version 8.3.3 (8E3004b)).

I wasn’t sure if there was a place in build settings to tell xcode to ignore these kinds of compilation errors.

Oh BTW if anyone is using XCode there is a beta out for Xcode 9 and it actually has refactoring included so yay!

So my implementation looks like.

FString GetValidGuess()
{
    EGuessStatus Status = EGuessStatus::Invalid_Status;

do {
    int32 CurrentTry = BCGame.GetCurrentTry();
    // Get a guess from the user
    std::cout << "Your Current Try Is: " << CurrentTry << std::endl;
    FString Guess = "";
    std::cout << "Enter you guess: ";
    getline( std::cin, Guess);
    
    // Submit valid guess to the game
    // Print Number of Bulls And Cows
    Status = BCGame.CheckGuessValidity(Guess);
    
    switch(Status)
    {
        case EGuessStatus::Wrong_Length:
            std::cout << "Please enter a " << BCGame.GetHiddenWordLength() << " letter word.\n";
            break;
        case EGuessStatus::Not_Lowercase:
            std::cout << "Please enter only lowercase isograms.\n";
            break;
        case EGuessStatus::Invalid_Characters:
            std::cout << "Please only use letter no numbers or special characters.\n";
            break;
        case EGuessStatus::Not_Isogram:
            std::cout << "Please only enter isograms.\n";
            break;
        default:
            return Guess;
    }
    std::cout << std::endl;
} while(Status != EGuessStatus::OK);
return "";
}

Privacy & Terms