summaryrefslogtreecommitdiff
path: root/libcxx/test/std/utilities/function.objects/func.wrap/func.wrap.badcall/visibility_inlines_hidden.cpp
blob: fe5e49f71578709e66294e584abd832afb8f0a47 (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
//===----------------------------------------------------------------------===//
//
// 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
//
//===----------------------------------------------------------------------===//

// ADDITIONAL_COMPILE_FLAGS: -fvisibility-inlines-hidden

// When there is a weak hidden symbol in user code and a strong definition
// in the library, we test that the linker relies on the library version,
// as the default weak resolution semantics don't favour weak local definitions
// for XCOFF. This creates a conflict on std::bad_function_call, which is used
// by the std::function template instantiated in main.
#include <functional>
#include "test_macros.h"
#include "assert.h"

void foo() {}

void test_call() {
  std::function<void()> r(foo);
  r();
}

void test_throw() {
#ifndef TEST_HAS_NO_EXCEPTIONS
  std::function<int()> f;
  try {
    f();
    assert(false);
  } catch (const std::bad_function_call&) {
    return;
  }
  assert(false);
#endif // TEST_HAS_NO_EXCEPTIONS
}

int main(int, char**) {
  test_call();
  test_throw();
  return 0;
}