From e03ef3ecb6e86aa78a64119f30e683ee474ddb56 Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Wed, 26 Jan 2022 12:43:45 +1300 Subject: [PATCH] Support foo.bar in constant expressions --- CHANGES.current | 4 ++++ Examples/test-suite/constant_expr.i | 7 +++++++ Source/CParse/parser.y | 2 -- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/CHANGES.current b/CHANGES.current index b52bf0bf1..b70946f5d 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -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 diff --git a/Examples/test-suite/constant_expr.i b/Examples/test-suite/constant_expr.i index 7cb529f8a..2dc730acf 100644 --- a/Examples/test-suite/constant_expr.i +++ b/Examples/test-suite/constant_expr.i @@ -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; + %} diff --git a/Source/CParse/parser.y b/Source/CParse/parser.y index 05e476967..e809ee927 100644 --- a/Source/CParse/parser.y +++ b/Source/CParse/parser.y @@ -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);