[LLVMbugs] [Bug 18712] New: -Wshadow should ignore variables declared and shadowed in macros

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Mon Feb 3 10:37:08 PST 2014


http://llvm.org/bugs/show_bug.cgi?id=18712

            Bug ID: 18712
           Summary: -Wshadow should ignore variables declared and shadowed
                    in macros
           Product: clang
           Version: 3.4
          Hardware: Other
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: -New Bugs
          Assignee: unassignedclangbugs at nondot.org
          Reporter: htam at apple.com
                CC: llvmbugs at cs.uiuc.edu
    Classification: Unclassified

I get many false positives from -Wshadow for variables that are used by some
macros that are then nested into each other.  -Wshadow should ignore the case
where a variable is only used by a macro expansion.

$ cat foo.c
#include <stdio.h>

#define BAD_EXAMPLE(n)                         \
   {                                           \
       int __increment = 0;                    \
       while (__increment < n) {

#define WORSE                                  \
       }                                       \
       __increment += 1;                       \
   }

void foo(void) {
   BAD_EXAMPLE(100) {
       BAD_EXAMPLE(5) {
           puts("hi");
       } WORSE;
   } WORSE;
}

$ clang foo.c -c -o /dev/null -Wshadow
foo.c:15:9: warning: declaration shadows a local variable [-Wshadow]
       BAD_EXAMPLE(5) {
       ^
foo.c:5:13: note: expanded from macro 'BAD_EXAMPLE'
       int __increment = 0;                    \
           ^
foo.c:14:5: note: previous declaration is here
   BAD_EXAMPLE(100) {
   ^
foo.c:5:13: note: expanded from macro 'BAD_EXAMPLE'
       int __increment = 0;                    \
           ^
1 warning generated.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20140203/f177d07e/attachment.html>


More information about the llvm-bugs mailing list