Skip to content

add parentheses around min and max#377

Merged
HDembinski merged 1 commit into
boostorg:developfrom
jhcarl0814:add_parentheses_around_min_and_max
Dec 24, 2022
Merged

add parentheses around min and max#377
HDembinski merged 1 commit into
boostorg:developfrom
jhcarl0814:add_parentheses_around_min_and_max

Conversation

@jhcarl0814 jhcarl0814 mentioned this pull request Dec 24, 2022
@HDembinski

Copy link
Copy Markdown
Collaborator

Thanks for this. Did you just spot these or did you use an algorithm to find all cases of unprotected min/max?

@HDembinski

Copy link
Copy Markdown
Collaborator

Thanks, these look all good. It is rediculous that Windows enforces this workaround on everyone.

I don't like sprinkling the code with parenthesis because the reason is not clear unless you know about the Windows bug, but the only more obvious fix is incredibly verbose, so it is better this way. It is the technique used by Boost.Config. In max(...), one insert BOOST_PREVENT_MACRO_SUBSTITUATION between max and (...), like so:

        ct width = max BOOST_PREVENT_MACRO_SUBSTITUTION (ct(1),

@HDembinski HDembinski merged commit 78021d5 into boostorg:develop Dec 24, 2022
@jhcarl0814

Copy link
Copy Markdown
Contributor Author

@HDembinski Thank you for pointing out the standard way of doing the workaround.

I was copying the test code into the beginning of main of an existing project (wanted to use IDE debugger) when fixing the bugs of the PR. There were some other test code for other stuffs that caused me to #include<windows.h> in the past, that's how I got the min and max errors.

So I global searched min( and max( and added the parentheses. (Oh no! I missed the cases where there might be white spaces and comments between the identifier and parenthesis!)
(I agree that the windows.h's macro is really annoying.)

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