Skip to content

Ticket #7805: Ignore enumerators when simplifying known variables.#846

Merged
danmar merged 1 commit intocppcheck-opensource:masterfrom
simartin:ticket_7805
Dec 21, 2016
Merged

Ticket #7805: Ignore enumerators when simplifying known variables.#846
danmar merged 1 commit intocppcheck-opensource:masterfrom
simartin:ticket_7805

Conversation

@simartin
Copy link
Copy Markdown
Contributor

@simartin simartin commented Nov 6, 2016

Known variable simplification must be aware of enumerators and leave them untouched even if they are called the same as a constant variable.

@danmar
Copy link
Copy Markdown
Collaborator

danmar commented Nov 6, 2016

hmm.. did you try Token::isEnumerator() ?

@simartin
Copy link
Copy Markdown
Contributor Author

simartin commented Nov 6, 2016

I had not, thanks for the hint. I did right now, replacing isEnumerator(tok) by tok->isEnumerator() in my patch, and it does not work: the simplification occurs before the symbol database is built, hence the second XX flagged as enumerator.

@danmar
Copy link
Copy Markdown
Collaborator

danmar commented Nov 6, 2016

ok

@danmar
Copy link
Copy Markdown
Collaborator

danmar commented Nov 6, 2016

this solution can waste cpu. imagine a large array initialization with 1000 symbols:

buf[] = {a,a,a,b,b,b,c,c,c,..};

one alternative is that you have a "isEnumScope" flag. Every time a "}" is seen you clear it. When a "{" is seen you set it to true if it's an enum scope. However in the setVarIdPass1 it might be most clean to integrate this into the VarIdScopeInfo.

I don't look at this code often so .. do you think that would be more messy or less good for some reason?

@simartin
Copy link
Copy Markdown
Contributor Author

Updated patch with an alternative solution, as suggested.

@danmar danmar merged commit 426d1b4 into cppcheck-opensource:master Dec 21, 2016
@simartin simartin deleted the ticket_7805 branch December 21, 2016 20:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants