This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

about warning "cannot optimize loop, the loop counter may overflow"


Hi.

I have the following code:

static const std::string paths[] = { "file1", "file2", "file2" };
for (size_t i = 0; i < (sizeof(paths) / sizeof(paths[0])); ++i)
{
    if (access(paths[i], F_OK | R_OK) == 0)
    {
        return std::string(paths[i]);
    }
}

It results in error:

error: cannot optimize loop, the loop counter may overflow
[-Werror=unsafe-loop-optimizations]

(well, warning turned to error with -Werror) in the line "for (size_t i = ...".

Changing "std::string" in array's declaration into "char* const"
removes the warning (error). Why is that? I thought that this warning
comes from optimizer, which knows the exact size of "std::string"
object?
-- 
JÄdrzej Dudkiewicz

I really hate this damn machine, I wish that they would sell it.
It never does just what I want, but only what I tell it.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]