File tree Expand file tree Collapse file tree 2 files changed +13
-1
lines changed Expand file tree Collapse file tree 2 files changed +13
-1
lines changed Original file line number Diff line number Diff line change @@ -1551,7 +1551,7 @@ void CheckUnusedVar::checkStructMemberUsage()
15511551 }
15521552 // Member referenced in offsetof
15531553 if (Token::Match (tok, (" offsetof ( struct| " + scope.className + " , %name%" ).c_str ())) {
1554- tok = tok->astSibling ()-> astOperand2 ( );
1554+ tok = Token::simpleMatch ( tok->tokAt ( 2 ), " struct " ) ? tok-> tokAt ( 5 ) : tok-> tokAt ( 4 );
15551555 if (tok->str () == var.name ()) {
15561556 use = true ;
15571557 break ;
Original file line number Diff line number Diff line change @@ -71,6 +71,7 @@ class TestUnusedVar : public TestFixture {
7171 TEST_CASE (structmember24); // #10847
7272 TEST_CASE (structmember25);
7373 TEST_CASE (structmember26); // #13345
74+ TEST_CASE (structmember27); // #13367
7475 TEST_CASE (structmember_macro);
7576 TEST_CASE (classmember);
7677
@@ -1971,6 +1972,17 @@ class TestUnusedVar : public TestFixture {
19711972 ASSERT_EQUALS (" " , errout_str ());
19721973 }
19731974
1975+ void structmember27 () { // #13367
1976+ checkStructMemberUsage (" typedef struct pathNode_s {\n "
1977+ " struct pathNode_s* next;\n "
1978+ " } pathNode_t;\n "
1979+ " void f() {\n "
1980+ " x<pathNode_t, offsetof( pathNode_t, next )> y;\n "
1981+ " }\n " );
1982+ ASSERT_EQUALS (" " , // don't crash
1983+ errout_str ());
1984+ }
1985+
19741986 void structmember_macro () {
19751987 checkStructMemberUsageP (" #define S(n) struct n { int a, b, c; };\n "
19761988 " S(unused);\n " );
You can’t perform that action at this time.
0 commit comments