MAX() spurious compiler warning

Originator:s.fisher.ca
Number:rdar://10296999 Date Originated:17-Oct-2011 11:08 AM
Status:Open Resolved:
Product:Developer Tools Product Version:4.2 / 4D199
Classification:Other Bug Reproducible:Always
 
17-Oct-2011 11:08 AM Steven Fisher:
Summary:
With GCC_WARN_SHADOW set, MIN and MAX macros cause a warning when nested.

Steps to Reproduce:
1. Create a new Mac command line project.
2. Turn on GCC_WARN_SHADOW = YES.
3. Replace the hello world with code:
		CGFloat wantedScale = 1.5;
		CGFloat actualScale = MIN(2.0, MAX(1.0, wantedScale));
		NSLog(@"Scale is %f", actualScale);

Expected Results:
Code should compile without warning.

Actual Results:
"Declaration shadows a local variable."

Regression:

Notes:
The cause of the warning is the macro's expansion:

  CGFloat actualScale = ({ __typeof__(2.0) __a = (2.0); __typeof__(({ __typeof__(1.0) __a = (1.0); __typeof__(wantedScale) __b = (wantedScale); __a < __b ? __b : __a; })) __b = (({ __typeof__(1.0) __a = (1.0); __typeof__(wantedScale) __b = (wantedScale); __a < __b ? __b : __a; })); __a < __b ? __a : __b; });

Simplified a bit for readability, this is:

  CGFloat actualScale = ({ CGFloat __a = (2.0); CGFloat __b = (({ CGFloat __a = (1.0); CGFloat __b = (wantedScale); __a < __b ? __b : __a; })); __a < __b ? __a : __b; });

Of course, this makes sense. But it also fills my build with warnings when I do something completely valid. I want GCC_WARN_SHADOW to catch index and offset, not MIN(MAX()), MAX(MAX(),MAX()), etc.

Suggested fix: Don't show GCC_WARN_SHADOW warnings for identifiers prefixed with __.

Comments


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!