[clang] 22b65a3 - [NFC][Clang][ASTTests] Use ASSERT instead of EXPECT for nullptr checks

Michael Spencer via cfe-commits cfe-commits at lists.llvm.org
Wed Jan 4 17:33:35 PST 2023


Author: Michael Spencer
Date: 2023-01-04T17:33:12-08:00
New Revision: 22b65a329ac2621279ae211dd6a868198e68d149

URL: https://github.com/llvm/llvm-project/commit/22b65a329ac2621279ae211dd6a868198e68d149
DIFF: https://github.com/llvm/llvm-project/commit/22b65a329ac2621279ae211dd6a868198e68d149.diff

LOG: [NFC][Clang][ASTTests] Use ASSERT instead of EXPECT for nullptr checks

This avoids basically guaranteed crashes when the check fails.

Added: 
    

Modified: 
    clang/unittests/AST/DeclTest.cpp

Removed: 
    


################################################################################
diff  --git a/clang/unittests/AST/DeclTest.cpp b/clang/unittests/AST/DeclTest.cpp
index 6d525dc8ac3fe..940ff17f8c80f 100644
--- a/clang/unittests/AST/DeclTest.cpp
+++ b/clang/unittests/AST/DeclTest.cpp
@@ -404,7 +404,7 @@ TEST(Decl, ImplicitlyDeclaredAllocationFunctionsInModules) {
                          hasParameter(0, hasType(isUnsignedInteger())))
                 .bind("operator new"),
             Ctx));
-  EXPECT_TRUE(SizedOperatorNew->getOwningModule());
+  ASSERT_TRUE(SizedOperatorNew->getOwningModule());
   EXPECT_TRUE(SizedOperatorNew->getOwningModule()->isGlobalModule());
 
   // void* operator new(std::size_t, std::align_val_t);
@@ -416,7 +416,7 @@ TEST(Decl, ImplicitlyDeclaredAllocationFunctionsInModules) {
                 hasParameter(1, hasType(enumDecl(hasName("std::align_val_t")))))
                 .bind("operator new"),
             Ctx));
-  EXPECT_TRUE(SizedAlignedOperatorNew->getOwningModule());
+  ASSERT_TRUE(SizedAlignedOperatorNew->getOwningModule());
   EXPECT_TRUE(SizedAlignedOperatorNew->getOwningModule()->isGlobalModule());
 
   // void* operator new[](std::size_t);
@@ -426,7 +426,7 @@ TEST(Decl, ImplicitlyDeclaredAllocationFunctionsInModules) {
                          hasParameter(0, hasType(isUnsignedInteger())))
                 .bind("operator new[]"),
             Ctx));
-  EXPECT_TRUE(SizedArrayOperatorNew->getOwningModule());
+  ASSERT_TRUE(SizedArrayOperatorNew->getOwningModule());
   EXPECT_TRUE(SizedArrayOperatorNew->getOwningModule()->isGlobalModule());
 
   // void* operator new[](std::size_t, std::align_val_t);
@@ -438,7 +438,7 @@ TEST(Decl, ImplicitlyDeclaredAllocationFunctionsInModules) {
                 hasParameter(1, hasType(enumDecl(hasName("std::align_val_t")))))
                 .bind("operator new[]"),
             Ctx));
-  EXPECT_TRUE(SizedAlignedArrayOperatorNew->getOwningModule());
+  ASSERT_TRUE(SizedAlignedArrayOperatorNew->getOwningModule());
   EXPECT_TRUE(
       SizedAlignedArrayOperatorNew->getOwningModule()->isGlobalModule());
 
@@ -450,7 +450,7 @@ TEST(Decl, ImplicitlyDeclaredAllocationFunctionsInModules) {
                 hasParameter(0, hasType(pointerType(pointee(voidType())))))
                 .bind("operator delete"),
             Ctx));
-  EXPECT_TRUE(Delete->getOwningModule());
+  ASSERT_TRUE(Delete->getOwningModule());
   EXPECT_TRUE(Delete->getOwningModule()->isGlobalModule());
 
   // void operator delete(void*, std::align_val_t) noexcept;
@@ -462,7 +462,7 @@ TEST(Decl, ImplicitlyDeclaredAllocationFunctionsInModules) {
                 hasParameter(1, hasType(enumDecl(hasName("std::align_val_t")))))
                 .bind("operator delete"),
             Ctx));
-  EXPECT_TRUE(AlignedDelete->getOwningModule());
+  ASSERT_TRUE(AlignedDelete->getOwningModule());
   EXPECT_TRUE(AlignedDelete->getOwningModule()->isGlobalModule());
 
   // Sized deallocation is not enabled by default. So we skip it here.
@@ -475,7 +475,7 @@ TEST(Decl, ImplicitlyDeclaredAllocationFunctionsInModules) {
                 hasParameter(0, hasType(pointerType(pointee(voidType())))))
                 .bind("operator delete[]"),
             Ctx));
-  EXPECT_TRUE(ArrayDelete->getOwningModule());
+  ASSERT_TRUE(ArrayDelete->getOwningModule());
   EXPECT_TRUE(ArrayDelete->getOwningModule()->isGlobalModule());
 
   // void operator delete[](void*, std::align_val_t) noexcept;
@@ -487,6 +487,6 @@ TEST(Decl, ImplicitlyDeclaredAllocationFunctionsInModules) {
                 hasParameter(1, hasType(enumDecl(hasName("std::align_val_t")))))
                 .bind("operator delete[]"),
             Ctx));
-  EXPECT_TRUE(AlignedArrayDelete->getOwningModule());
+  ASSERT_TRUE(AlignedArrayDelete->getOwningModule());
   EXPECT_TRUE(AlignedArrayDelete->getOwningModule()->isGlobalModule());
 }


        


More information about the cfe-commits mailing list