diff options
author | Marc Chevrier <marc.chevrier@gmail.com> | 2021-09-13 14:55:00 (GMT) |
---|---|---|
committer | Marc Chevrier <marc.chevrier@gmail.com> | 2021-09-14 15:42:02 (GMT) |
commit | 79362cf11715ffc5acd48ec884559d69a35a655d (patch) | |
tree | f2d2f64b5949f3e23acd80a12c2f21c096c08b48 | |
parent | 69c0a5daf98958ba6ad4311781ec72fe8b9bfb0a (diff) | |
download | CMake-79362cf11715ffc5acd48ec884559d69a35a655d.zip CMake-79362cf11715ffc5acd48ec884559d69a35a655d.tar.gz CMake-79362cf11715ffc5acd48ec884559d69a35a655d.tar.bz2 |
cmProp: cm::string_view cast operator must be explicit
To avoid ambiguity on std::string assigment between the following two
cmProp cast operators:
* operator const std::string&() const noexcept
* operator cm::string_view() const noexcept
-rw-r--r-- | Source/CPack/cmCPackGenerator.cxx | 4 | ||||
-rw-r--r-- | Source/cmCoreTryCompile.cxx | 6 | ||||
-rw-r--r-- | Source/cmMakefile.h | 4 | ||||
-rw-r--r-- | Source/cmProperty.h | 5 | ||||
-rw-r--r-- | Source/cmSeparateArgumentsCommand.cxx | 3 | ||||
-rw-r--r-- | Source/cmStringAlgorithms.h | 26 |
6 files changed, 39 insertions, 9 deletions
diff --git a/Source/CPack/cmCPackGenerator.cxx b/Source/CPack/cmCPackGenerator.cxx index 1527e80..4ad25ad 100644 --- a/Source/CPack/cmCPackGenerator.cxx +++ b/Source/CPack/cmCPackGenerator.cxx @@ -167,7 +167,7 @@ int cmCPackGenerator::PrepareNames() } cmProp algoSignature = this->GetOption("CPACK_PACKAGE_CHECKSUM"); if (algoSignature) { - if (!cmCryptoHash::New(algoSignature)) { + if (!cmCryptoHash::New(*algoSignature)) { cmCPackLogger(cmCPackLog::LOG_ERROR, "Cannot recognize algorithm: " << algoSignature << std::endl); @@ -1129,7 +1129,7 @@ int cmCPackGenerator::DoPackage() /* Prepare checksum algorithm*/ cmProp algo = this->GetOption("CPACK_PACKAGE_CHECKSUM"); - std::unique_ptr<cmCryptoHash> crypto = cmCryptoHash::New(algo); + std::unique_ptr<cmCryptoHash> crypto = cmCryptoHash::New(*algo); /* * Copy the generated packages to final destination diff --git a/Source/cmCoreTryCompile.cxx b/Source/cmCoreTryCompile.cxx index 0fd48f0..0c85d28 100644 --- a/Source/cmCoreTryCompile.cxx +++ b/Source/cmCoreTryCompile.cxx @@ -606,7 +606,7 @@ int cmCoreTryCompile::TryCompileCode(std::vector<std::string> const& argv, std::string langFlags = "CMAKE_" + li + "_FLAGS"; cmProp flags = this->Makefile->GetDefinition(langFlags); fprintf(fout, "set(CMAKE_%s_FLAGS %s)\n", li.c_str(), - cmOutputConverter::EscapeForCMake(flags).c_str()); + cmOutputConverter::EscapeForCMake(*flags).c_str()); fprintf(fout, "set(CMAKE_%s_FLAGS \"${CMAKE_%s_FLAGS}" " ${COMPILE_DEFINITIONS}\")\n", @@ -645,7 +645,7 @@ int cmCoreTryCompile::TryCompileCode(std::vector<std::string> const& argv, cmStrCat("CMAKE_", li, "_FLAGS_", cfg); cmProp flagsCfg = this->Makefile->GetDefinition(langFlagsCfg); fprintf(fout, "set(%s %s)\n", langFlagsCfg.c_str(), - cmOutputConverter::EscapeForCMake(flagsCfg).c_str()); + cmOutputConverter::EscapeForCMake(*flagsCfg).c_str()); } } break; } @@ -678,7 +678,7 @@ int cmCoreTryCompile::TryCompileCode(std::vector<std::string> const& argv, cmProp exeLinkFlags = this->Makefile->GetDefinition("CMAKE_EXE_LINKER_FLAGS"); fprintf(fout, "set(CMAKE_EXE_LINKER_FLAGS %s)\n", - cmOutputConverter::EscapeForCMake(exeLinkFlags).c_str()); + cmOutputConverter::EscapeForCMake(*exeLinkFlags).c_str()); } break; } diff --git a/Source/cmMakefile.h b/Source/cmMakefile.h index bdcab3b..bad9d91 100644 --- a/Source/cmMakefile.h +++ b/Source/cmMakefile.h @@ -286,6 +286,10 @@ public: * can be used in CMake to refer to lists, directories, etc. */ void AddDefinition(const std::string& name, cm::string_view value); + void AddDefinition(const std::string& name, cmProp value) + { + this->AddDefinition(name, *value); + } /** * Add bool variable definition to the build. */ diff --git a/Source/cmProperty.h b/Source/cmProperty.h index 3a0a5be..4179187 100644 --- a/Source/cmProperty.h +++ b/Source/cmProperty.h @@ -66,7 +66,10 @@ public: explicit operator bool() const noexcept { return this->Value != nullptr; } operator const std::string&() const noexcept { return this->operator*(); } - operator cm::string_view() const noexcept { return this->operator*(); } + explicit operator cm::string_view() const noexcept + { + return this->operator*(); + } /** * Does the value indicate a true or ON value? diff --git a/Source/cmSeparateArgumentsCommand.cxx b/Source/cmSeparateArgumentsCommand.cxx index 52b1a44..c2fc45c 100644 --- a/Source/cmSeparateArgumentsCommand.cxx +++ b/Source/cmSeparateArgumentsCommand.cxx @@ -4,6 +4,7 @@ #include <algorithm> +#include <cm/string_view> #include <cmext/string_view> #include "cmArgumentParser.h" @@ -81,7 +82,7 @@ bool cmSeparateArgumentsCommand(std::vector<std::string> const& args, } if (unparsedArguments.empty()) { - status.GetMakefile().AddDefinition(var, {}); + status.GetMakefile().AddDefinition(var, cm::string_view{}); return true; } diff --git a/Source/cmStringAlgorithms.h b/Source/cmStringAlgorithms.h index 20061e9..33ab403 100644 --- a/Source/cmStringAlgorithms.h +++ b/Source/cmStringAlgorithms.h @@ -94,6 +94,13 @@ std::vector<std::string> cmTokenize(cm::string_view str, cm::string_view sep); */ void cmExpandList(cm::string_view arg, std::vector<std::string>& argsOut, bool emptyArgs = false); +inline void cmExpandList(cmProp arg, std::vector<std::string>& argsOut, + bool emptyArgs = false) +{ + if (arg) { + cmExpandList(*arg, argsOut, emptyArgs); + } +} /** * Expand out any arguments in the string range [@a first, @a last) that have @@ -115,6 +122,14 @@ void cmExpandLists(InputIt first, InputIt last, */ std::vector<std::string> cmExpandedList(cm::string_view arg, bool emptyArgs = false); +inline std::vector<std::string> cmExpandedList(cmProp arg, + bool emptyArgs = false) +{ + if (!arg) { + return {}; + } + return cmExpandedList(*arg, emptyArgs); +} /** * Same as cmExpandList but a new vector is created containing the expanded @@ -217,6 +232,13 @@ inline bool cmIsInternallyOn(const char* val) } return cmIsInternallyOn(cm::string_view(val)); } +inline bool cmIsInternallyOn(cmProp val) +{ + if (!val) { + return false; + } + return cmIsInternallyOn(*val); +} /** Check for non-empty Property/Variable value. */ inline bool cmNonempty(cm::string_view val) @@ -297,7 +319,7 @@ inline bool cmHasPrefix(cm::string_view str, cmProp prefix) return false; } - return str.compare(0, prefix->size(), prefix) == 0; + return str.compare(0, prefix->size(), *prefix) == 0; } /** Returns true if string @a str starts with string @a prefix. */ @@ -328,7 +350,7 @@ inline bool cmHasSuffix(cm::string_view str, cmProp suffix) } return str.size() >= suffix->size() && - str.compare(str.size() - suffix->size(), suffix->size(), suffix) == 0; + str.compare(str.size() - suffix->size(), suffix->size(), *suffix) == 0; } /** Returns true if string @a str ends with string @a suffix. */ |