Skip to content

Add foreach emulation for older compilers - #1138

Merged
danmar merged 1 commit into
cppcheck-opensource:masterfrom
pfultz2:foreach
Mar 29, 2018
Merged

danmar merged 1 commit into
cppcheck-opensource:masterfrom
pfultz2:foreach

Conversation

@pfultz2

@pfultz2 pfultz2 commented Mar 28, 2018

Copy link
Copy Markdown
Collaborator

This provides a fallback for older compilers that don't support the for-range loop. I wasn't able to test this with gcc 4.4 as it doesn't build with cppcheck, but it should work as it does support both auto and rvalue references.

@danmar

danmar commented Mar 28, 2018

Copy link
Copy Markdown
Collaborator

wait.. I don't want to have a FOREACH macro. we will move to real c++11 sooner or later. It's too soon today, but in a few years it should be ok.

@pfultz2

pfultz2 commented Mar 28, 2018

Copy link
Copy Markdown
Collaborator Author

Sure, I just figure its something we could use now, and when we move to C++11 its easy to do sed -r 's/FOREACH[(]([^,]*),/for(\1:/g' to get rid of the macro. Of course, if the minimum compilers will be gcc 4.6 and MSVC 2010, then the std::foreach+lambda can be used.

@danmar

danmar commented Mar 28, 2018 •

Copy link
Copy Markdown
Collaborator

I dont like this FOREACH macro. so I close this PR.

I would like that we carefully move to the real range for loops.

I don't have a good picture about what compilers people use to compile cppcheck. that is something we want to have before we start using the real range for loops everywhere. I don't know how we can get a good picture.

I discussed in the chat about writing a compiler warning if an old gcc version is used. In short it would tell the user to please report the version to cppcheck project. maybe a forum would be nice so we can ask the users if there is a workaround or if they are going to upgrade.

@danmar danmar closed this Mar 28, 2018
@pfultz2

pfultz2 commented Mar 28, 2018

Copy link
Copy Markdown
Collaborator Author

I dont like this FOREACH macro.

Why?

I would like that we carefully move to the real range for loops.

And this allows us to use real range for loops without it breaking on older compilers. I dont really see the problem.

@danmar danmar reopened this Mar 29, 2018
@danmar

danmar commented Mar 29, 2018

Copy link
Copy Markdown
Collaborator

sorry.. I have changed my mind. this emulation is acceptable. range for loops is the c++11 feature I miss the most right now.

@danmar
danmar merged commit 70da3ac into cppcheck-opensource:master Mar 29, 2018
@pfultz2
pfultz2 deleted the foreach branch May 19, 2019 05:25
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