xref: /aosp_15_r20/external/clang/test/CodeGenCXX/weak-external.cpp (revision 67e74705e28f6214e480b399dd47ea732279e315)
1*67e74705SXin Li // RUN: %clang_cc1 -fcxx-exceptions -fexceptions -triple %itanium_abi_triple %s -S -emit-llvm -o - | FileCheck %s
2*67e74705SXin Li // PR4262
3*67e74705SXin Li 
4*67e74705SXin Li // CHECK-NOT: _ZNSs12_S_constructIPKcEEPcT_S3_RKSaIcESt20forward_iterator_tag
5*67e74705SXin Li 
6*67e74705SXin Li // The "basic_string" extern template instantiation declaration is supposed to
7*67e74705SXin Li // suppress the implicit instantiation of non-inline member functions. Make sure
8*67e74705SXin Li // that we suppress the implicit instantiation of non-inline member functions
9*67e74705SXin Li // defined out-of-line. That we aren't instantiating the basic_string
10*67e74705SXin Li // constructor when we shouldn't be. Such an instantiation forces the implicit
11*67e74705SXin Li // instantiation of _S_construct<const char*>. Since _S_construct is a member
12*67e74705SXin Li // template, it's instantiation is *not* suppressed (despite being in
13*67e74705SXin Li // basic_string<char>), so we would emit it as a weak definition.
14*67e74705SXin Li 
15*67e74705SXin Li #define _LIBCPP_EXCEPTION_ABI __attribute__ ((__visibility__("default")))
16*67e74705SXin Li #define _LIBCPP_INLINE_VISIBILITY __attribute__ ((__visibility__("hidden"), __always_inline__))
17*67e74705SXin Li #define _LIBCPP_VISIBLE __attribute__ ((__visibility__("default")))
18*67e74705SXin Li #if (__has_feature(cxx_noexcept))
19*67e74705SXin Li #  define _NOEXCEPT noexcept
20*67e74705SXin Li #  define _NOEXCEPT_(x) noexcept(x)
21*67e74705SXin Li #else
22*67e74705SXin Li #  define _NOEXCEPT throw()
23*67e74705SXin Li #  define _NOEXCEPT_(x)
24*67e74705SXin Li #endif
25*67e74705SXin Li 
26*67e74705SXin Li namespace std  // purposefully not using versioning namespace
27*67e74705SXin Li {
28*67e74705SXin Li 
29*67e74705SXin Li template<class charT> struct char_traits;
30*67e74705SXin Li template<class T>     class allocator;
31*67e74705SXin Li template <class _CharT,
32*67e74705SXin Li           class _Traits = char_traits<_CharT>,
33*67e74705SXin Li           class _Allocator = allocator<_CharT> >
34*67e74705SXin Li     class _LIBCPP_VISIBLE basic_string;
35*67e74705SXin Li typedef basic_string<char, char_traits<char>, allocator<char> > string;
36*67e74705SXin Li 
37*67e74705SXin Li class _LIBCPP_EXCEPTION_ABI exception
38*67e74705SXin Li {
39*67e74705SXin Li public:
exception()40*67e74705SXin Li     _LIBCPP_INLINE_VISIBILITY exception() _NOEXCEPT {}
41*67e74705SXin Li     virtual ~exception() _NOEXCEPT;
42*67e74705SXin Li     virtual const char* what() const _NOEXCEPT;
43*67e74705SXin Li };
44*67e74705SXin Li 
45*67e74705SXin Li class _LIBCPP_EXCEPTION_ABI runtime_error
46*67e74705SXin Li     : public exception
47*67e74705SXin Li {
48*67e74705SXin Li private:
49*67e74705SXin Li     void* __imp_;
50*67e74705SXin Li public:
51*67e74705SXin Li     explicit runtime_error(const string&);
52*67e74705SXin Li     explicit runtime_error(const char*);
53*67e74705SXin Li 
54*67e74705SXin Li     runtime_error(const runtime_error&) _NOEXCEPT;
55*67e74705SXin Li     runtime_error& operator=(const runtime_error&) _NOEXCEPT;
56*67e74705SXin Li 
57*67e74705SXin Li     virtual ~runtime_error() _NOEXCEPT;
58*67e74705SXin Li 
59*67e74705SXin Li     virtual const char* what() const _NOEXCEPT;
60*67e74705SXin Li };
61*67e74705SXin Li 
62*67e74705SXin Li }
63*67e74705SXin Li 
dummysymbol()64*67e74705SXin Li void dummysymbol() {
65*67e74705SXin Li   throw(std::runtime_error("string"));
66*67e74705SXin Li }
67