[llvm] 7445f1e - [NFC] Mark Expected<T>::assertIsChecked() as const

via llvm-commits llvm-commits at lists.llvm.org
Thu Jul 8 06:31:59 PDT 2021


Author: xndcn
Date: 2021-07-08T21:30:23+08:00
New Revision: 7445f1e4dcd4525ab1f04f3cebfda341ec2eb716

URL: https://github.com/llvm/llvm-project/commit/7445f1e4dcd4525ab1f04f3cebfda341ec2eb716
DIFF: https://github.com/llvm/llvm-project/commit/7445f1e4dcd4525ab1f04f3cebfda341ec2eb716.diff

LOG: [NFC] Mark Expected<T>::assertIsChecked() as const

Some const methods of Expected<T> invoke assertIsChecked(),
so we should mark it as const too.

Differential Revision: https://reviews.llvm.org/D105292

Added: 
    

Modified: 
    llvm/include/llvm/Support/Error.h
    llvm/unittests/Support/ErrorTest.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/Support/Error.h b/llvm/include/llvm/Support/Error.h
index 4b7ab58263698..e8f340e452ef6 100644
--- a/llvm/include/llvm/Support/Error.h
+++ b/llvm/include/llvm/Support/Error.h
@@ -703,7 +703,7 @@ template <class T> class LLVM_NODISCARD Expected {
   }
 #endif
 
-  void assertIsChecked() {
+  void assertIsChecked() const {
 #if LLVM_ENABLE_ABI_BREAKING_CHECKS
     if (LLVM_UNLIKELY(Unchecked))
       fatalUncheckedExpected();

diff  --git a/llvm/unittests/Support/ErrorTest.cpp b/llvm/unittests/Support/ErrorTest.cpp
index 37289e1b23562..d9e86fdd617ef 100644
--- a/llvm/unittests/Support/ErrorTest.cpp
+++ b/llvm/unittests/Support/ErrorTest.cpp
@@ -556,7 +556,7 @@ TEST(Error, ExpectedWithReferenceType) {
 TEST(Error, UncheckedExpectedInSuccessModeDestruction) {
   EXPECT_DEATH({ Expected<int> A = 7; },
                "Expected<T> must be checked before access or destruction.")
-    << "Unchecekd Expected<T> success value did not cause an abort().";
+      << "Unchecked Expected<T> success value did not cause an abort().";
 }
 #endif
 
@@ -565,9 +565,13 @@ TEST(Error, UncheckedExpectedInSuccessModeDestruction) {
 // Test runs in debug mode only.
 #if LLVM_ENABLE_ABI_BREAKING_CHECKS
 TEST(Error, UncheckedExpectedInSuccessModeAccess) {
-  EXPECT_DEATH({ Expected<int> A = 7; *A; },
-               "Expected<T> must be checked before access or destruction.")
-    << "Unchecekd Expected<T> success value did not cause an abort().";
+  EXPECT_DEATH(
+      {
+        const Expected<int> A = 7;
+        *A;
+      },
+      "Expected<T> must be checked before access or destruction.")
+      << "Unchecked Expected<T> success value did not cause an abort().";
 }
 #endif
 
@@ -576,9 +580,13 @@ TEST(Error, UncheckedExpectedInSuccessModeAccess) {
 // Test runs in debug mode only.
 #if LLVM_ENABLE_ABI_BREAKING_CHECKS
 TEST(Error, UncheckedExpectedInSuccessModeAssignment) {
-  EXPECT_DEATH({ Expected<int> A = 7; A = 7; },
-               "Expected<T> must be checked before access or destruction.")
-    << "Unchecekd Expected<T> success value did not cause an abort().";
+  EXPECT_DEATH(
+      {
+        Expected<int> A = 7;
+        A = 7;
+      },
+      "Expected<T> must be checked before access or destruction.")
+      << "Unchecked Expected<T> success value did not cause an abort().";
 }
 #endif
 


        


More information about the llvm-commits mailing list