Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 38 additions & 3 deletions src/dmd/cppmangle.d
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,40 @@ private final class CppMangleVisitor : Visitor
!getQualifier(s)); // at global level
}

/************************
* Determine if type is a C++ fundamental type.
* Params:
* t = type to check
* Returns:
* true if it is a fundamental type
*/
static bool isFundamentalType(Type t)
{
// First check the target whether some specific ABI is being followed.
bool isFundamental = void;
if (target.cppFundamentalType(t, isFundamental))
return isFundamental;

if (auto te = t.isTypeEnum())
{
// Peel off enum type from special types.
if (te.sym.isSpecial())
t = te.memType();
}

// Fundamental arithmetic types:
// 1. integral types: bool, char, int, ...
// 2. floating point types: float, double, real
// 3. void
// 4. null pointer: std::nullptr_t (since C++11)
if (t.ty == Tvoid || t.ty == Tbool)
return true;
else if (t.ty == Tnull && global.params.cplusplus >= CppStdRevision.cpp11)
return true;
else
return t.isTypeBasic() && (t.isintegral() || t.isreal());
}

/******************************
* Write the mangled representation of a template argument.
* Params:
Expand Down Expand Up @@ -1090,7 +1124,8 @@ private final class CppMangleVisitor : Visitor
*/
void writeBasicType(Type t, char p, char c)
{
if (p || t.isConst())
// Only do substitutions for non-fundamental types.
if (!isFundamentalType(t) || t.isConst())
{
if (substitute(t))
return;
Expand Down Expand Up @@ -1296,8 +1331,8 @@ extern(C++):
// Handle any target-specific basic types.
if (auto tm = target.cppTypeMangle(t))
{
// Only do substitution for mangles that are longer than 1 character.
if (tm[1] != 0 || t.isConst())
// Only do substitutions for non-fundamental types.
if (!isFundamentalType(t) || t.isConst())
{
if (substitute(t))
return;
Expand Down
13 changes: 13 additions & 0 deletions src/dmd/target.d
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,19 @@ struct Target
return t;
}

/**
* Checks whether type is a vendor-specific fundamental type.
* Params:
* t = type to inspect
* isFundamental = where to store result
* Returns:
* true if isFundamental was set by function
*/
extern (C++) bool cppFundamentalType(const Type t, ref bool isFundamental)
{
return false;
}

/**
* Default system linkage for the target.
* Returns:
Expand Down
14 changes: 14 additions & 0 deletions test/runnable/cppa.d
Original file line number Diff line number Diff line change
Expand Up @@ -727,6 +727,19 @@ void test16()
static assert(0);
}

/****************************************/
/+ FIXME: Requires C++11 compiler.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the time has come to segment tests by C++ version.
You can create a separate file, let's say cppa_11.d, and use:

 // EXTRA_CPP_SOURCES: cppa_11.cpp
// CXXFLAGS: -std=c++11

To test C++11-specific behaviors

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice idea though it can probably be done as another PR.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we should be rushing to merge PRs without any tests in them.
And it's not a large change to do either, moving a bit of code to a new file, so I really don't understand the hurry.

alias nullptr_t = typeof(null);

extern (C++) void testnull(nullptr_t);
extern (C++) void testnullnull(nullptr_t, nullptr_t);

void test17()
{
testnull(null);
testnullnull(null, null);
}
+/

/****************************************/

Expand Down Expand Up @@ -1611,6 +1624,7 @@ void main()
test13289();
test15();
test16();
//test17();
func13707();
func13932(S13932!(-1)(0));
foo13337(S13337());
Expand Down
14 changes: 14 additions & 0 deletions test/runnable/extra-files/cppb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,20 @@ unsigned long testul(unsigned long ul)
return ul + sizeof(unsigned long);
}

/******************************************/
/* FIXME: Requires C++11 compiler.
void testnull(nullptr_t n)
{
assert(n == NULL);
}

void testnullnull(nullptr_t n1, nullptr_t n2)
{
assert(n1 == NULL);
assert(n2 == NULL);
}
*/

/******************************************/

struct S13707
Expand Down