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-exception
6 //
7 //===----------------------------------------------------------------------===//
8
9 // This test relies on `typeid` and thus requires `-frtti`.
10 // UNSUPPORTED: no-rtti
11
12 // Make sure that we don't get ODR violations with __exception_guard when
13 // linking together TUs compiled with different values of -f[no-]exceptions.
14
15 // RUN: %{cxx} %s %{flags} %{compile_flags} -c -o %t.except.o -O1 -fexceptions
16 // RUN: %{cxx} %s %{flags} %{compile_flags} -c -o %t.noexcept.o -O1 -fno-exceptions
17 // RUN: %{cxx} %{flags} %{link_flags} -o %t.exe %t.except.o %t.noexcept.o
18 // RUN: %{run}
19
20 #include <__utility/exception_guard.h>
21 #include <cassert>
22 #include <cstring>
23 #include <typeinfo>
24
25 struct Rollback {
operator ()Rollback26 void operator()() {}
27 };
28
29 #if defined(__cpp_exceptions) && __cpp_exceptions >= 199711L
30
31 const char* func();
32
main(int,char **)33 int main(int, char**) {
34 assert(std::strcmp(typeid(std::__exception_guard<Rollback>).name(), func()) != 0);
35
36 return 0;
37 }
38
39 #else
40
func()41 const char* func() { return typeid(std::__exception_guard<Rollback>).name(); }
42
43 #endif
44