Add parentheses around '&&' between '||' for gcc

The GNU compiler warns about possible operator precedence mistakes and
asks for explicit parentheses (-Wparentheses).  We add the parentheses
to silence the warning.  This also fixes one real logic error in the
find_package() implementation by correcting expression evaluation order.
This commit is contained in:
Brad King 2009-09-11 08:18:15 -04:00
parent e0df0495e5
commit b41a548d86
11 changed files with 47 additions and 42 deletions

View File

@ -359,10 +359,11 @@ int main (int argc, char *argv[])
"CPack project name not specified" << std::endl);
parsed = 0;
}
if ( parsed && !(mf->GetDefinition("CPACK_PACKAGE_VERSION")
|| mf->GetDefinition("CPACK_PACKAGE_VERSION_MAJOR") &&
mf->GetDefinition("CPACK_PACKAGE_VERSION_MINOR")
&& mf->GetDefinition("CPACK_PACKAGE_VERSION_PATCH")) )
if (parsed &&
!(mf->GetDefinition("CPACK_PACKAGE_VERSION") ||
(mf->GetDefinition("CPACK_PACKAGE_VERSION_MAJOR") &&
mf->GetDefinition("CPACK_PACKAGE_VERSION_MINOR") &&
mf->GetDefinition("CPACK_PACKAGE_VERSION_PATCH"))))
{
cmCPack_Log(&log, cmCPackLog::LOG_ERROR,
"CPack project version not specified" << std::endl

View File

@ -611,8 +611,8 @@ void cmCTestBuildHandler::GenerateXMLLogScraped(std::ostream& os)
it != ew.end() && (numErrorsAllowed || numWarningsAllowed); it++ )
{
cmCTestBuildErrorWarning *cm = &(*it);
if (cm->Error && numErrorsAllowed ||
!cm->Error && numWarningsAllowed)
if ((cm->Error && numErrorsAllowed) ||
(!cm->Error && numWarningsAllowed))
{
if (cm->Error)
{
@ -681,8 +681,8 @@ void cmCTestBuildHandler::GenerateXMLLogScraped(std::ostream& os)
<< "</PreContext>\n"
<< "\t\t<PostContext>" << cmXMLSafe(cm->PostContext).Quotes(false);
// is this the last warning or error, if so notify
if (cm->Error && !numErrorsAllowed ||
!cm->Error && !numWarningsAllowed)
if ((cm->Error && !numErrorsAllowed) ||
(!cm->Error && !numWarningsAllowed))
{
os << "\nThe maximum number of reported warnings or errors has been "
"reached!!!\n";

View File

@ -231,7 +231,8 @@ void cmCursesMainForm::RePost()
{
cmCacheManager::CacheIterator mit =
this->CMakeInstance->GetCacheManager()->GetCacheIterator((*it)->GetValue());
if (mit.IsAtEnd() || !this->AdvancedMode && mit.GetPropertyAsBool("ADVANCED"))
if (mit.IsAtEnd() ||
(!this->AdvancedMode && mit.GetPropertyAsBool("ADVANCED")))
{
continue;
}
@ -259,7 +260,8 @@ void cmCursesMainForm::RePost()
{
cmCacheManager::CacheIterator mit =
this->CMakeInstance->GetCacheManager()->GetCacheIterator((*it)->GetValue());
if (mit.IsAtEnd() || !this->AdvancedMode && mit.GetPropertyAsBool("ADVANCED"))
if (mit.IsAtEnd() ||
(!this->AdvancedMode && mit.GetPropertyAsBool("ADVANCED")))
{
continue;
}
@ -327,7 +329,8 @@ void cmCursesMainForm::Render(int left, int top, int width, int height)
{
cmCacheManager::CacheIterator mit =
this->CMakeInstance->GetCacheManager()->GetCacheIterator((*it)->GetValue());
if (mit.IsAtEnd() || !this->AdvancedMode && mit.GetPropertyAsBool("ADVANCED"))
if (mit.IsAtEnd() ||
(!this->AdvancedMode && mit.GetPropertyAsBool("ADVANCED")))
{
continue;
}
@ -344,7 +347,8 @@ void cmCursesMainForm::Render(int left, int top, int width, int height)
{
cmCacheManager::CacheIterator mit =
this->CMakeInstance->GetCacheManager()->GetCacheIterator((*it)->GetValue());
if (mit.IsAtEnd() || !this->AdvancedMode && mit.GetPropertyAsBool("ADVANCED"))
if (mit.IsAtEnd() ||
(!this->AdvancedMode && mit.GetPropertyAsBool("ADVANCED")))
{
continue;
}
@ -914,10 +918,10 @@ void cmCursesMainForm::HandleInput()
this->SearchMode = false;
}
*/
else if ( key >= 'a' && key <= 'z' ||
key >= 'A' && key <= 'Z' ||
key >= '0' && key <= '9' ||
key == '_' )
else if ((key >= 'a' && key <= 'z') ||
(key >= 'A' && key <= 'Z') ||
(key >= '0' && key <= '9') ||
(key == '_' ))
{
if ( this->SearchString.size() < static_cast<std::string::size_type>(x-10) )
{

View File

@ -87,12 +87,12 @@ bool cmCMakeMinimumRequired
}
// Compare the version numbers.
if(current_major < required_major ||
current_major == required_major &&
current_minor < required_minor ||
current_major == required_major &&
current_minor == required_minor &&
current_patch < required_patch)
if((current_major < required_major) ||
(current_major == required_major &&
current_minor < required_minor) ||
(current_major == required_major &&
current_minor == required_minor &&
current_patch < required_patch))
{
// The current version is too low.
cmOStringStream e;
@ -110,7 +110,7 @@ bool cmCMakeMinimumRequired
return false;
}
if (required_major < 2 || required_major == 2 && required_minor < 4)
if (required_major < 2 || (required_major == 2 && required_minor < 4))
{
this->Makefile->SetPolicyVersion("2.4");
}

View File

@ -298,8 +298,8 @@ bool cmExecuteProcessCommand
while((p = cmsysProcess_WaitForData(cp, &data, &length, 0), p))
{
// Put the output in the right place.
if(p == cmsysProcess_Pipe_STDOUT && !output_quiet ||
p == cmsysProcess_Pipe_STDERR && !error_quiet && merge_output)
if((p == cmsysProcess_Pipe_STDOUT && !output_quiet) ||
(p == cmsysProcess_Pipe_STDERR && !error_quiet && merge_output))
{
if(output_variable.empty())
{

View File

@ -590,7 +590,7 @@ bool cmFileCommand::HandleStringsCommand(std::vector<std::string> const& args)
{
// Ignore CR character to make output always have UNIX newlines.
}
else if(c >= 0x20 && c < 0x7F || c == '\t' || c == '\f' ||
else if((c >= 0x20 && c < 0x7F) || c == '\t' || c == '\f' ||
(c == '\n' && newline_consume))
{
// This is an ASCII character that may be part of a string.
@ -1973,7 +1973,7 @@ bool cmFileInstaller::HandleInstallDestination()
if ( ch1 != '/' )
{
int relative = 0;
if ( ( ch1 >= 'a' && ch1 <= 'z' || ch1 >= 'A' && ch1 <= 'Z' ) &&
if (((ch1 >= 'a' && ch1 <= 'z') || (ch1 >= 'A' && ch1 <= 'Z')) &&
ch2 == ':' )
{
// Assume windows

View File

@ -900,13 +900,13 @@ void cmFindPackageCommand::FindConfig()
bool found = false;
// Search for frameworks.
if(!found && this->SearchFrameworkFirst || this->SearchFrameworkOnly)
if(!found && (this->SearchFrameworkFirst || this->SearchFrameworkOnly))
{
found = this->FindFrameworkConfig();
}
// Search for apps.
if(!found && this->SearchAppBundleFirst || this->SearchAppBundleOnly)
if(!found && (this->SearchAppBundleFirst || this->SearchAppBundleOnly))
{
found = this->FindAppBundleConfig();
}
@ -1136,8 +1136,8 @@ void cmFindPackageCommand::AddPrefixesSystemEnvironment()
std::string const& d = *i;
// If the path is a PREFIX/bin case then add its parent instead.
if(d.size() >= 4 && strcmp(d.c_str()+d.size()-4, "/bin") == 0 ||
d.size() >= 5 && strcmp(d.c_str()+d.size()-5, "/sbin") == 0)
if((d.size() >= 4 && strcmp(d.c_str()+d.size()-4, "/bin") == 0) ||
(d.size() >= 5 && strcmp(d.c_str()+d.size()-5, "/sbin") == 0))
{
this->AddPathInternal(cmSystemTools::GetFilenamePath(d), EnvPath);
}

View File

@ -497,7 +497,7 @@ bool cmPolicies::ApplyPolicyVersion(cmMakefile *mf,
}
// it is an error if the policy version is less than 2.4
if (majorVer < 2 || majorVer == 2 && minorVer < 4)
if (majorVer < 2 || (majorVer == 2 && minorVer < 4))
{
mf->IssueMessage(cmake::FATAL_ERROR,
"An attempt was made to set the policy version of CMake to something "

View File

@ -134,9 +134,9 @@ bool cmSetCommand
// we should be nice and try to catch some simple screwups if the last or
// next to last args are CACHE then they screwed up. If they used FORCE
// without CACHE they screwed up
if (args[args.size() - 1] == "CACHE" ||
args.size() > 1 && args[args.size() - 2] == "CACHE" ||
force && !cache)
if ((args[args.size() - 1] == "CACHE") ||
(args.size() > 1 && args[args.size() - 2] == "CACHE") ||
(force && !cache))
{
this->SetError("given invalid arguments for CACHE mode.");
return false;

View File

@ -510,12 +510,12 @@ std::vector<cmStdString> cmSystemTools::ParseArguments(const char* command)
bool win_path = false;
if ( command[0] != '/' && command[1] == ':' && command[2] == '\\' ||
command[0] == '\"' && command[1] != '/' && command[2] == ':'
&& command[3] == '\\' ||
command[0] == '\'' && command[1] != '/' && command[2] == ':'
&& command[3] == '\\' ||
command[0] == '\\' && command[1] == '\\')
if ((command[0] != '/' && command[1] == ':' && command[2] == '\\') ||
(command[0] == '\"' && command[1] != '/' && command[2] == ':'
&& command[3] == '\\') ||
(command[0] == '\'' && command[1] != '/' && command[2] == ':'
&& command[3] == '\\') ||
(command[0] == '\\' && command[1] == '\\'))
{
win_path = true;
}

View File

@ -56,7 +56,7 @@ bool cmUtilitySourceCommand
{
haveCacheValue = (cacheValue &&
(strstr(cacheValue, "(IntDir)") == 0 ||
intDir && strcmp(intDir, "$(IntDir)") == 0) &&
(intDir && strcmp(intDir, "$(IntDir)") == 0)) &&
(this->Makefile->GetCacheMajorVersion() != 0 &&
this->Makefile->GetCacheMinorVersion() != 0 ));
}