-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
…, if their headers aren't part of a Clang module.
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// RUN: %ldc -cpp-args -std=c++11 -cpp-cachedir=%t.cache -of %t %s | ||
// RUN: %t > %t.out | ||
// RUN: FileCheck %s < %t.out | ||
|
||
modmap (C++) "macro.h"; | ||
|
||
import (C++) _; | ||
import std.stdio : writeln; | ||
|
||
void main() | ||
{ | ||
writeln("my_macro = ", my_macro); | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong. |
||
// CHECK: my_macro = 42 | ||
|
||
writeln("empty_macro = ", empty_macro); | ||
// CHECK: empty_macro = true | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#pragma once | ||
|
||
#define my_macro 42 | ||
#define empty_macro |
3 comments
on commit da8a975
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks for the quick fix! (at least to non-function macros)
Instead of polluting global namespace, how about introducing it in another namespace, eg:
import (C++) _; // imports everything (but not macros)
import (C++) __macros; // imports all macros
import (C++) __macros : my_macro ; // ...
alternative name: __preprocessor
especially important because lots of #includes define tons of macros (often in a very non-trivial, system specific way that abuses the preprocessor)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought about that, but it would mean that if the author of a C++ library chooses to turn its #define
constants into C++11 constexpr
constants for example, user C++ code won't require any update, but D code would break (although a preemptive solution to support multiple versions of the library would be to import _
). IMHO pollution is still preferable, kinda..
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- I hear your point, here's a better option:
pragma(calypso_allow_macro)
import (C++) _ : cv_32F, cv_64F;
NOTE: using pragma is the way to go; it's flexible (eg we can attach a pragma to a single or multiple statements via pragma(x) foo;
, pragma(x): foo; //till end
, pragma(x){foo;...}
; they can be combined with other pragmas, and it allows for future features, eg:
pragma(calypso_recursive_namespace)
pragma(calypso_allow_macro)
import (C++) _ ; // imports all namespaces recursively
// make sure known at compile time
static assert(my_macro == 42);