• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 checks that we retain extern template instantiation declarations
10 // for members of <locale> even when the debug mode is enabled, which is
11 // necessary for correctness. See https://llvm.org/D94718 for details.
12 
13 // UNSUPPORTED: !libcpp-has-debug-mode
14 // UNSUPPORTED: no-localization
15 // UNSUPPORTED: cant-build-shared-library
16 
17 // This test relies on linking a shared library and then passing that shared
18 // library as input when linking an executable; this is generally not supported
19 // on Windows (GNU ld supports it, but MS link.exe and LLD don't) - one has to
20 // use an import library instead. (Additionally, the test uses the -fPIC
21 // option which clang doesn't accept on Windows.)
22 // UNSUPPORTED: windows
23 
24 // XFAIL: LIBCXX-AIX-FIXME
25 
26 // RUN: %{cxx} %{flags} %{compile_flags} %s %{link_flags} -fPIC -DTU1 -fvisibility=hidden -shared -o %t.lib
27 // RUN: cd %T && %{cxx} %{flags} %{compile_flags} %s ./%basename_t.tmp.lib %{link_flags} -DTU2 -fvisibility=hidden -o %t.exe
28 // RUN: %{exec} %t.exe
29 
30 #include <cassert>
31 #include <cstdio>
32 #include <sstream>
33 #include <string>
34 
35 std::string __attribute__((visibility("default"))) numToString(int x);
36 
37 #if defined(TU1)
38 
numToString(int x)39 std::string numToString(int x) {
40   std::stringstream ss;
41   ss << x;
42   return ss.str();
43 }
44 
45 #elif defined(TU2)
46 
main(int,char **)47 int main(int, char**) {
48   std::string s = numToString(42);
49   assert(s == "42");
50 
51   return 0;
52 }
53 
54 #endif
55