diff options
Diffstat (limited to 'clang-tools-extra/test')
-rw-r--r-- | clang-tools-extra/test/clang-tidy/cert-static-object-exception.cpp | 29 |
1 files changed, 27 insertions, 2 deletions
diff --git a/clang-tools-extra/test/clang-tidy/cert-static-object-exception.cpp b/clang-tools-extra/test/clang-tidy/cert-static-object-exception.cpp index 9181dc7ebaa..5c07c8d606a 100644 --- a/clang-tools-extra/test/clang-tidy/cert-static-object-exception.cpp +++ b/clang-tools-extra/test/clang-tidy/cert-static-object-exception.cpp @@ -1,7 +1,7 @@ -// RUN: clang-tidy %s -checks="-*,cert-err58-cpp" -- -std=c++11 -target x86_64-pc-linux-gnu \ +// RUN: clang-tidy %s -checks="-*,cert-err58-cpp" -- -std=c++17 -target x86_64-pc-linux-gnu \ // RUN: | FileCheck %s -check-prefix=CHECK-EXCEPTIONS \ // RUN: -implicit-check-not="{{warning|error}}:" -// RUN: clang-tidy %s -checks="-*,cert-err58-cpp" -- -DNONEXCEPTIONS -fno-exceptions -std=c++11 -target x86_64-pc-linux-gnu \ +// RUN: clang-tidy %s -checks="-*,cert-err58-cpp" -- -DNONEXCEPTIONS -fno-exceptions -std=c++17 -target x86_64-pc-linux-gnu \ // RUN: | FileCheck %s -allow-empty -check-prefix=CHECK-NONEXCEPTIONS \ // RUN: -implicit-check-not="{{warning|error}}:" @@ -236,3 +236,28 @@ int baz = foo(0); // Not OK; throws at runtime when exceptions are enabled. } // namespace pr35457 #endif // NONEXCEPTIONS +namespace pr39777 { +struct S { S(); }; +struct T { T() noexcept; }; + +auto Okay1 = []{ S s; }; +auto Okay2 = []{ (void)new int; }; +auto NotOkay1 = []{ S s; return 12; }(); // Because the lambda call is not noexcept +// CHECK-EXCEPTIONS: :[[@LINE-1]]:6: warning: initialization of 'NotOkay1' with static storage duration may throw an exception that cannot be caught [cert-err58-cpp] +// CHECK-EXCEPTIONS: :[[@LINE-7]]:12: note: possibly throwing constructor declared here +auto NotOkay2 = []() noexcept { S s; return 12; }(); // Because S::S() is not noexcept +// CHECK-EXCEPTIONS: :[[@LINE-1]]:6: warning: initialization of 'NotOkay2' with static storage duration may throw an exception that cannot be caught [cert-err58-cpp] +// CHECK-EXCEPTIONS: :[[@LINE-10]]:12: note: possibly throwing constructor declared here +auto Okay3 = []() noexcept { T t; return t; }(); + +struct U { + U() noexcept; + auto getBadLambda() const noexcept { + return []{ S s; return s; }; + } +}; +auto Okay4 = []{ U u; return u.getBadLambda(); }(); +auto NotOkay3 = []() noexcept { U u; return u.getBadLambda(); }()(); // Because the lambda returned and called is not noexcept +// CHECK-EXCEPTIONS: :[[@LINE-1]]:6: warning: initialization of 'NotOkay3' with static storage duration may throw an exception that cannot be caught [cert-err58-cpp] +// CHECK-EXCEPTIONS: :[[@LINE-6]]:12: note: possibly throwing function declared here +} |