Properly handle C99 complex types even in C++ mode

Use the `_Complex` keyword rather than the `complex` macro.

Fixes #1487.
This commit is contained in:
Leo Singer 2020-04-02 15:08:08 -04:00
commit 13260f95b0
6 changed files with 24 additions and 20 deletions

View file

@ -912,6 +912,10 @@ int yylex(void) {
yylval.type = NewSwigType(T_COMPLEX);
return (TYPE_COMPLEX);
}
if (strcmp(yytext, "_Complex") == 0) {
yylval.type = NewSwigType(T_COMPLEX);
return (TYPE_COMPLEX);
}
if (strcmp(yytext, "restrict") == 0)
return (yylex());
}

View file

@ -6232,19 +6232,19 @@ primitive_type_list : type_specifier {
} else if (Cmp($1.type,"double") == 0) {
if (Cmp($2.type,"long") == 0) {
$$.type = NewString("long double");
} else if (Cmp($2.type,"complex") == 0) {
$$.type = NewString("double complex");
} else if (Cmp($2.type,"complex") == 0 || Cmp($2.type,"_Complex") == 0) {
$$.type = NewString("double _Complex");
} else {
err = 1;
}
} else if (Cmp($1.type,"float") == 0) {
if (Cmp($2.type,"complex") == 0) {
$$.type = NewString("float complex");
if (Cmp($2.type,"complex") == 0 || Cmp($2.type,"_Complex") == 0) {
$$.type = NewString("float _Complex");
} else {
err = 1;
}
} else if (Cmp($1.type,"complex") == 0) {
$$.type = NewStringf("%s complex", $2.type);
} else if (Cmp($1.type,"complex") == 0 || Cmp($1.type,"_Complex") == 0) {
$$.type = NewStringf("%s _Complex", $2.type);
} else {
err = 1;
}

View file

@ -1453,9 +1453,9 @@ int SwigType_type(const SwigType *t) {
return T_DOUBLE;
if (strcmp(c, "long double") == 0)
return T_LONGDOUBLE;
if (!cparse_cplusplus && (strcmp(c, "float complex") == 0))
if (!cparse_cplusplus && (strcmp(c, "float _Complex") == 0))
return T_FLTCPLX;
if (!cparse_cplusplus && (strcmp(c, "double complex") == 0))
if (!cparse_cplusplus && (strcmp(c, "double _Complex") == 0))
return T_DBLCPLX;
if (!cparse_cplusplus && (strcmp(c, "complex") == 0))
return T_COMPLEX;