40 lines · cpp
1//===----------------------------------------------------------------------===//2//3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.4// See https://llvm.org/LICENSE.txt for license information.5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception6//7//===----------------------------------------------------------------------===//8 9// MSVC warning C4611: interaction between '_setjmp' and C++ object destruction is non-portable10// ADDITIONAL_COMPILE_FLAGS(cl-style-warnings): /wd461111 12// test <csetjmp>13 14#include <csetjmp>15#include <cassert>16#include <type_traits>17 18int main(int, char**) {19 std::jmp_buf jb;20 21 switch (setjmp(jb)) {22 // First time we set the buffer, the function should return 023 case 0:24 break;25 26 // If it returned 42, then we're coming from the std::longjmp call below27 case 42:28 return 0;29 30 // Otherwise, something is wrong31 default:32 return 1;33 }34 35 std::longjmp(jb, 42);36 static_assert(std::is_same<decltype(std::longjmp(jb, 0)), void>::value, "");37 38 return 1;39}40