Try to unbreak Win build differently after 973519826e

Looks like the MS STL wants StringMapKeyIterator::operator*() to be const.
Return the result by copy instead of reference to do that.
Assigning to a hash map key iterator doesn't make sense anyways.

Also reverts 123f811fe5 which is now hopefully no longer needed.

Differential Revision: https://reviews.llvm.org/D109167
This commit is contained in:
Nico Weber 2021-09-02 12:42:48 -04:00
parent a270de359f
commit 5881dcff7e
3 changed files with 19 additions and 10 deletions

View file

@ -59,9 +59,8 @@ std::string x86::getX86TargetCPU(const Driver &D, const ArgList &Args,
}
StringRef CPU = ArchMap.lookup(A->getValue());
if (CPU.empty()) {
std::vector<StringRef> ValidArchs;
for (StringRef Key : ArchMap.keys())
ValidArchs.push_back(Key);
std::vector<StringRef> ValidArchs{ArchMap.keys().begin(),
ArchMap.keys().end()};
sort(ValidArchs);
D.Diag(diag::warn_drv_invalid_arch_name_with_suggestion)
<< A->getValue() << (Triple.getArch() == llvm::Triple::x86)

View file

@ -478,13 +478,9 @@ public:
explicit StringMapKeyIterator(StringMapConstIterator<ValueTy> Iter)
: base(std::move(Iter)) {}
StringRef &operator*() {
Key = this->wrapped()->getKey();
return Key;
StringRef operator*() const {
return this->wrapped()->getKey();
}
private:
StringRef Key;
};
} // end namespace llvm

View file

@ -308,7 +308,21 @@ TEST_F(StringMapTest, InsertOrAssignTest) {
EXPECT_EQ(0, try1.first->second.copy);
}
TEST_F(StringMapTest, IterMapKeys) {
TEST_F(StringMapTest, IterMapKeysVector) {
StringMap<int> Map;
Map["A"] = 1;
Map["B"] = 2;
Map["C"] = 3;
Map["D"] = 3;
std::vector<StringRef> Keys{Map.keys().begin(), Map.keys().end()};
llvm::sort(Keys);
std::vector<StringRef> Expected{{"A", "B", "C", "D"}};
EXPECT_EQ(Expected, Keys);
}
TEST_F(StringMapTest, IterMapKeysSmallVector) {
StringMap<int> Map;
Map["A"] = 1;
Map["B"] = 2;