diff --git a/Units/parser-c.r/properties.c.d/args.ctags b/Units/parser-c.r/properties.c.d/args.ctags new file mode 100644 index 0000000000..ba41cbfabf --- /dev/null +++ b/Units/parser-c.r/properties.c.d/args.ctags @@ -0,0 +1,4 @@ +--sort=no +--kinds-c=* +--fields=+x +--fields-c=+{properties} diff --git a/Units/parser-c.r/properties.c.d/expected.tags b/Units/parser-c.r/properties.c.d/expected.tags new file mode 100644 index 0000000000..cab4ac2b4b --- /dev/null +++ b/Units/parser-c.r/properties.c.d/expected.tags @@ -0,0 +1,5 @@ +T input.c /^static struct T {int t;} f1(int i)$/;" s file: +t input.c /^static struct T {int t;} f1(int i)$/;" m struct:T typeref:typename:int file: +f1 input.c /^static struct T {int t;} f1(int i)$/;" f typeref:struct:T file: properties:static +i input.c /^static struct T {int t;} f1(int i)$/;" z function:f1 typeref:typename:int file: +r input.c /^ struct T r = {.t = i};$/;" l function:f1 typeref:struct:T file: diff --git a/Units/parser-c.r/properties.c.d/input.c b/Units/parser-c.r/properties.c.d/input.c new file mode 100644 index 0000000000..d08487fd35 --- /dev/null +++ b/Units/parser-c.r/properties.c.d/input.c @@ -0,0 +1,9 @@ +// See #3943. +// static struct S {int s;} fS1(int i); + +/* This is invalid input as C++ code. */ +static struct T {int t;} f1(int i) +{ + struct T r = {.t = i}; + return r; +} diff --git a/parsers/cxx/cxx_parser.c b/parsers/cxx/cxx_parser.c index 65fe77c69e..e545e6b4f8 100644 --- a/parsers/cxx/cxx_parser.c +++ b/parsers/cxx/cxx_parser.c @@ -550,6 +550,25 @@ static bool cxxParserParseEnumStructClassOrUnionFullDeclarationTrailer( if(cxxTokenTypeIs(g_cxx.pToken,CXXTokenTypeOpeningBracket)) { CXX_DEBUG_PRINT("Found opening bracket: possibly a function declaration?"); + + // Revert keyword states. + // Here we assume the following kind of input: + // + // static struct S {...} fn (...) { ... } + // + // To fill properties: field of fn with "static", g_cxx.uKeywordState + // must be set here. + // + // See cxxParserEmitFunctionTags. + // + // NOTE: C++ doesn't accept such kind of input. So we propagate + // the state only meaningful in C languages. + g_cxx.uKeywordState |= uKeywordState & (0 + | CXXParserKeywordStateSeenStatic + | CXXParserKeywordStateSeenInline + | CXXParserKeywordStateSeenExtern + | CXXParserKeywordStateSeenAttributeDeprecated + ); if(!cxxParserParseBlockHandleOpeningBracket()) { CXX_DEBUG_LEAVE_TEXT("Failed to handle the opening bracket");