Support foo.bar in constant expressions

This commit is contained in:
Olly Betts 2022-01-26 12:43:45 +13:00
commit e03ef3ecb6
3 changed files with 11 additions and 2 deletions

View file

@ -7,6 +7,10 @@ the issue number to the end of the URL: https://github.com/swig/swig/issues/
Version 4.1.0 (in progress)
===========================
2022-01-25: olly
Constant expressions now support member access with `.` such as
`foo.bar`. Previous this only worked in a case like `x->foo.bar`.
2022-01-25: olly
#2091 Support most cases of `sizeof` applied to an expression
in constant expressions. Previously there was only support for

View file

@ -14,4 +14,11 @@ isPointer = false
};
};
// Test handling of ID PERIOD ID in constant expressions (supported since 4.1.0).
struct A {
int i;
};
constexpr A a{42};
const int N = a.i;
%}

View file

@ -6521,12 +6521,10 @@ exprmem : ID ARROW ID {
$$ = $1;
Printf($$.val, "->%s", $3);
}
/* This generates a shift-reduce
| ID PERIOD ID {
$$.val = NewStringf("%s.%s", $1, $3);
$$.type = 0;
}
*/
| exprmem PERIOD ID {
$$ = $1;
Printf($$.val, ".%s", $3);