Skip to content

Commit 999fc68

Browse files
committed
Fix wrapping of compile-time constants in C code
1 parent 52fe84b commit 999fc68

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

Source/Modules/fortran.cxx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,14 @@ bool is_node_constructor(Node *n) {
4444
return (Cmp(Getattr(n, "nodeType"), "constructor") == 0 || Getattr(n, "handled_as_constructor"));
4545
}
4646

47+
/*!
48+
* \brief Whether a node is a compile-time constant that isn't acutally defined in client code.
49+
*/
50+
bool has_constant_storage(Node *n) {
51+
String *s = Getattr(n, "storage");
52+
return s && (Cmp(s, "%constant") == 0);
53+
}
54+
4755
/* -------------------------------------------------------------------------
4856
* \brief Print a comma-joined line of items to the given output.
4957
*/
@@ -2927,7 +2935,7 @@ int FORTRAN::constantWrapper(Node *n) {
29272935
// Wrap as an external link-time variable (since it could be a complex expression or something that only C can evaluate)
29282936
String *symname = Getattr(n, "sym:name");
29292937
String *wname = NULL;
2930-
if (!CPlusPlus || Swig_storage_isexternc(n)) {
2938+
if ((!CPlusPlus && !has_constant_storage(n)) || Swig_storage_isexternc(n)) {
29312939
// Bind directly to the symbol
29322940
wname = Copy(symname);
29332941
} else {

0 commit comments

Comments
 (0)