[llvm] r211244 - PR10140 - StringPool's PooledStringPtr has non-const operator== causing bad OR-result.
Nikola Smiljanic
popizdeh at gmail.com
Wed Jun 18 17:26:49 PDT 2014
Author: nikola
Date: Wed Jun 18 19:26:49 2014
New Revision: 211244
URL: http://llvm.org/viewvc/llvm-project?rev=211244&view=rev
Log:
PR10140 - StringPool's PooledStringPtr has non-const operator== causing bad OR-result.
Mark conversion operator explicit and const qualify comparison operators.
Added:
llvm/trunk/unittests/Support/StringPool.cpp
Modified:
llvm/trunk/include/llvm/Support/StringPool.h
llvm/trunk/unittests/Support/CMakeLists.txt
Modified: llvm/trunk/include/llvm/Support/StringPool.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/StringPool.h?rev=211244&r1=211243&r2=211244&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Support/StringPool.h (original)
+++ llvm/trunk/include/llvm/Support/StringPool.h Wed Jun 18 19:26:49 2014
@@ -128,10 +128,10 @@ namespace llvm {
}
inline const char *operator*() const { return begin(); }
- inline operator bool() const { return S != nullptr; }
+ inline explicit operator bool() const { return S != nullptr; }
- inline bool operator==(const PooledStringPtr &That) { return S == That.S; }
- inline bool operator!=(const PooledStringPtr &That) { return S != That.S; }
+ inline bool operator==(const PooledStringPtr &That) const { return S == That.S; }
+ inline bool operator!=(const PooledStringPtr &That) const { return S != That.S; }
};
} // End llvm namespace
Modified: llvm/trunk/unittests/Support/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/Support/CMakeLists.txt?rev=211244&r1=211243&r2=211244&view=diff
==============================================================================
--- llvm/trunk/unittests/Support/CMakeLists.txt (original)
+++ llvm/trunk/unittests/Support/CMakeLists.txt Wed Jun 18 19:26:49 2014
@@ -30,6 +30,7 @@ add_llvm_unittest(SupportTests
ProgramTest.cpp
RegexTest.cpp
SourceMgrTest.cpp
+ StringPool.cpp
SwapByteOrderTest.cpp
ThreadLocalTest.cpp
TimeValueTest.cpp
Added: llvm/trunk/unittests/Support/StringPool.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/Support/StringPool.cpp?rev=211244&view=auto
==============================================================================
--- llvm/trunk/unittests/Support/StringPool.cpp (added)
+++ llvm/trunk/unittests/Support/StringPool.cpp Wed Jun 18 19:26:49 2014
@@ -0,0 +1,31 @@
+//===- llvm/unittest/Support/ThreadLocalTest.cpp - Therad Local tests ---===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "llvm/Support/StringPool.h"
+#include "gtest/gtest.h"
+
+using namespace llvm;
+
+namespace {
+
+TEST(PooledStringPtrTest, OperatorEquals) {
+ StringPool pool;
+ const PooledStringPtr a = pool.intern("a");
+ const PooledStringPtr b = pool.intern("b");
+ EXPECT_FALSE(a == b);
+}
+
+TEST(PooledStringPtrTest, OperatorNotEquals) {
+ StringPool pool;
+ const PooledStringPtr a = pool.intern("a");
+ const PooledStringPtr b = pool.intern("b");
+ EXPECT_TRUE(a != b);
+}
+
+}
More information about the llvm-commits
mailing list