Skip to content

Commit

Permalink
Fixes Issue 19194 - version for -mscrtlib specification
Browse files Browse the repository at this point in the history
Add __CXXLIB__ predefined enum.
  • Loading branch information
TurkeyMan committed Sep 19, 2018
1 parent a705f11 commit 0563a79
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 0 deletions.
8 changes: 8 additions & 0 deletions changelog/mscrt_ver.dd
@@ -0,0 +1,8 @@
Add `__CXXLIB__` built-in enum.

Query the C++ library version for the compilation target at compile time, eg:
---
static if (__CXXLIB__ == "libcmtd") { ... }
---

Currently only supported for MS-COFF output, and will be an empty string for other targets.
1 change: 1 addition & 0 deletions src/dmd/doc.d
Expand Up @@ -2126,6 +2126,7 @@ private bool isReservedName(const(char)[] str)
"__VENDOR__",
"__VERSION__",
"__EOF__",
"__CXXLIB__",
"__LOCAL_SIZE",
"___tls_get_addr",
"__entrypoint",
Expand Down
1 change: 1 addition & 0 deletions src/dmd/id.d
Expand Up @@ -159,6 +159,7 @@ immutable Msgtable[] msgtable =
{ "VENDOR", "__VENDOR__" },
{ "VERSIONX", "__VERSION__" },
{ "EOFX", "__EOF__" },
{ "CXXLIB", "__CXXLIB__" },

{ "nan" },
{ "infinity" },
Expand Down
18 changes: 18 additions & 0 deletions src/dmd/lexer.d
Expand Up @@ -530,6 +530,24 @@ class Lexer : ErrorHandler
t.ustring = global.compiler.vendor;
goto Lstr;
}
else if (id == Id.CXXLIB)
{
// TODO: other targets might also like to populate this with knowledge for library authors
// additional plumbing required...
if (!global.params.mscrtlib)
{
t.ustring = "";
}
else
{
size_t len = strlen(global.params.mscrtlib) + 1;
char* lower = cast(char*)mem.xmalloc(len);
foreach (i; 0 .. len)
lower[i] = cast(char)tolower(global.params.mscrtlib[i]);
t.ustring = lower;
}
goto Lstr;
}
else if (id == Id.TIMESTAMP)
{
t.ustring = timestamp.ptr;
Expand Down
11 changes: 11 additions & 0 deletions test/compilable/cpp.d
@@ -0,0 +1,11 @@

// Test C++ features.

version(CRuntime_Microsoft)
{
static assert(__CXXLIB__ == "libcmt");
}
else
{
static assert(__CXXLIB__.length == 0);
}

0 comments on commit 0563a79

Please sign in to comment.