| 1 |
// DISABLED: win32 win64 |
| 2 |
// REQUIRED_ARGS: -extern-std=c++11 |
| 3 |
/* |
| 4 |
* Test C++ abi-tag name mangling. |
| 5 |
* https://issues.dlang.org/show_bug.cgi?id=19949 |
| 6 |
*/ |
| 7 |
|
| 8 |
import core.attribute; |
| 9 |
|
| 10 |
extern(C++): |
| 11 |
|
| 12 |
alias Tuple(A...) = A; |
| 13 |
enum foo_bar = gnuAbiTag("foo", "bar"); |
| 14 |
|
| 15 |
@foo_bar |
| 16 |
struct S |
| 17 |
{ |
| 18 |
int i; |
| 19 |
this(int); |
| 20 |
} |
| 21 |
|
| 22 |
@foo_bar |
| 23 |
extern __gshared int a; |
| 24 |
static assert(a.mangleof == "_Z1aB3barB3foo"); |
| 25 |
|
| 26 |
extern __gshared S b; |
| 27 |
static assert(b.mangleof == "_Z1bB3barB3foo"); |
| 28 |
|
| 29 |
@foo_bar |
| 30 |
int f(); |
| 31 |
static assert(f.mangleof == "_Z1fB3barB3foov"); |
| 32 |
|
| 33 |
S gs(int); |
| 34 |
S gss(S, int); |
| 35 |
static assert(gs.mangleof == "_Z2gsB3barB3fooi"); |
| 36 |
static assert(gss.mangleof == "_Z3gss1SB3barB3fooi"); |
| 37 |
|
| 38 |
@foo_bar |
| 39 |
S fss(S, int); |
| 40 |
static assert(gs.mangleof == "_Z2gsB3barB3fooi"); |
| 41 |
|
| 42 |
T gt(T)(int); |
| 43 |
T gtt(T)(T, int); |
| 44 |
static assert(gt!S.mangleof == "_Z2gtI1SB3barB3fooET_i"); |
| 45 |
static assert(gtt!S.mangleof == "_Z3gttI1SB3barB3fooET_S1_i"); |
| 46 |
|
| 47 |
@foo_bar |
| 48 |
T ft(T)(int); |
| 49 |
// matches Clang and GCC <= 6 |
| 50 |
static assert(ft!S.mangleof == "_Z2ftB3barB3fooI1SB3barB3fooET_i"); |
| 51 |
|
| 52 |
@foo_bar |
| 53 |
T ftt(T)(T, int); |
| 54 |
// matches Clang and GCC <= 6 |
| 55 |
static assert(ftt!S.mangleof == "_Z3fttB3barB3fooI1SB3barB3fooET_S1_i"); |
| 56 |
|
| 57 |
// GCC >= 6 only |
| 58 |
@gnuAbiTag("ENN") |
| 59 |
enum E0 { a = 0xa, } |
| 60 |
E0 fe(); |
| 61 |
E0 fei(int i)(); |
| 62 |
static assert(fe.mangleof == "_Z2feB3ENNv"); |
| 63 |
static assert(fei!0.mangleof == "_Z3feiILi0EE2E0B3ENNv"); |
| 64 |
|
| 65 |
// Linux std::string |
| 66 |
// https://issues.dlang.org/show_bug.cgi?id=14956#c13 |
| 67 |
extern(C++, "std") |
| 68 |
{ |
| 69 |
struct allocator(T); |
| 70 |
struct char_traits(CharT); |
| 71 |
|
| 72 |
extern(C++, "__cxx11") |
| 73 |
{ |
| 74 |
@gnuAbiTag("cxx11") |
| 75 |
struct basic_string(CharT, Traits=char_traits!CharT, Allocator=allocator!CharT) |
| 76 |
{ |
| 77 |
const char* data(); |
| 78 |
size_t length() const; |
| 79 |
} |
| 80 |
} |
| 81 |
alias string_ = basic_string!char; |
| 82 |
} |
| 83 |
string_* toString(const char*); |
| 84 |
static assert(toString.mangleof == "_Z8toStringB5cxx11PKc"); |
| 85 |
|
| 86 |
@gnuAbiTag("A", "B") |
| 87 |
{ |
| 88 |
void fun0(); |
| 89 |
static assert(fun0.mangleof == "_Z4fun0B1AB1Bv"); |
| 90 |
} |
| 91 |
|
| 92 |
@gnuAbiTag("C", "D"): |
| 93 |
|
| 94 |
void fun1(); |
| 95 |
static assert(fun1.mangleof == "_Z4fun1B1CB1Dv"); |
| 96 |
|
| 97 |
void fun2(); |
| 98 |
static assert(fun2.mangleof == "_Z4fun2B1CB1Dv"); |
| 99 |
|
| 100 |
auto fun3() |
| 101 |
{ |
| 102 |
@gnuAbiTag("Nested") |
| 103 |
extern(C++) struct T {} |
| 104 |
return T(); |
| 105 |
} |
| 106 |
static assert(fun3.mangleof == "_Z4fun3B1CB1DB6Nestedv"); |