user2350858
user2350858

Reputation: 741

warning: control reaches end of non-void function [-Wreturn-type]

error message is in the tittle. does anyone know whats wrong? i want to clear this warning. im clueless.

   const std::string loadShaderFromFile(std::string shaderFilePath) {
        // load file
        std::fstream shaderFile(shaderFilePath.c_str(), std::ios::in);

        if(shaderFile.is_open()) {
            // help store the files buffer?
            std::stringstream shaderFileBuffer;
            // get files data by streaming the files stream into our buffer stream.
            shaderFileBuffer << shaderFile.rdbuf();
            // buffer contains the files data
            return shaderFileBuffer.str();
        }
    }

Upvotes: 0

Views: 6402

Answers (1)

Joseph Mansfield
Joseph Mansfield

Reputation: 110698

If shaderFile.is_open() returns false, your function will not reach a return statement. What do you want your function to return if the shaderFile doesn't open? Perhaps an empty string. Perhaps it should throw an exception (unless this is a normal thing to happen).

Upvotes: 2

Related Questions