summaryrefslogtreecommitdiffstats
path: root/libcxx/test/libcxx/debug/extern-templates.sh.cpp
blob: b2ed6a63d63038745d2f8b7b37109a7d5c7ab432 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
// -*- C++ -*-
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

// This test checks that we retain extern template instantiation declarations
// for members of <locale> even when the debug mode is enabled, which is
// necessary for correctness. See https://llvm.org/D94718 for details.

// UNSUPPORTED: libcxx-no-debug-mode
// UNSUPPORTED: libcpp-has-no-localization

// RUN: %{cxx} %{flags} %{compile_flags} %s %{link_flags} -fPIC -DTU1 -D_LIBCPP_DEBUG=1 -fvisibility=hidden -shared -o %t.lib
// RUN: cd %T && %{cxx} %{flags} %{compile_flags} %s %basename_t.tmp.lib %{link_flags} -fPIC -DTU2 -D_LIBCPP_DEBUG=1 -fvisibility=hidden -o %t.exe
// RUN: %{exec} %t.exe

#include <cassert>
#include <cstdio>
#include <sstream>
#include <string>

std::string __attribute__((visibility("default"))) numToString(int x);

#if defined(TU1)

std::string numToString(int x) {
  std::stringstream ss;
  ss << x;
  return ss.str();
}

#elif defined(TU2)

int main(int, char**) {
  std::string s = numToString(42);
  assert(s == "42");

  return 0;
}

#endif