Shadowed declaration is here

I am building a project that uses LLVM, and thus includes some of the LLVM header files.
As you can see below, I am getting lots of “shadowed declaration is here” warning messages.
My code still works OK, but how should we go about fixing all the warnings?

/usr/include/llvm-15/llvm/IR/ValueMap.h:250:43: warning: declaration of ‘Map’ shadows a member of ‘llvm::ValueMapCallbackVH<llvm::Value*, llvm::SCEVWrapPredicate::IncrementWrapFlags, llvm::ValueMapConfig<llvm::Value*, llvm::sys::SmartMutex > >’ [-Wshadow]
250 | ValueMapCallbackVH(KeyT Key, ValueMapT *Map)
| ~~~^
/usr/include/llvm-15/llvm/IR/ValueMap.h:248:14: note: shadowed declaration is here
248 | ValueMapT *Map;
| ^

/usr/include/llvm-15/llvm/ADT/Any.h:43:35: warning: declaration of ‘Value’ shadows a member of ‘llvm::Any::StorageImpl<const llvm::Module*>’ [-Wshadow]
43 | explicit StorageImpl(const T &Value) : Value(Value) {}
| ~^
/usr/include/llvm-15/llvm/ADT/Any.h:53:7: note: shadowed declaration is here
53 | T Value;
| ^

/usr/include/llvm-15/llvm/IR/ValueMap.h:340:26: warning: declaration of ‘I’ shadows a member of ‘llvm::ValueMapIterator<llvm::DenseMap<llvm::ValueMapCallbackVH<llvm::Value*, llvm::SCEVWrapPredicate::IncrementWrapFlags, llvm::ValueMapConfig<llvm::Value*, llvm::sys::SmartMutex > >, llvm::SCEVWrapPredicate::IncrementWrapFlags, llvm::DenseMapInfo<llvm::ValueMapCallbackVH<llvm::Value*, llvm::SCEVWrapPredicate::IncrementWrapFlags, llvm::ValueMapConfig<llvm::Value*, llvm::sys::SmartMutex > >, void>, llvm::detail::DenseMapPair<llvm::ValueMapCallbackVH<llvm::Value*, llvm::SCEVWrapPredicate::IncrementWrapFlags, llvm::ValueMapConfig<llvm::Value*, llvm::sys::SmartMutex > >, llvm::SCEVWrapPredicate::IncrementWrapFlags> >, llvm::Value*>’ [-Wshadow]
340 | ValueMapIterator(BaseT I) : I(I) {}
| ~~~~~~^
/usr/include/llvm-15/llvm/IR/ValueMap.h:330:9: note: shadowed declaration is here
330 | BaseT I;
| ^

/usr/include/llvm-15/llvm/ADT/StringMapEntry.h:77:32: warning: declaration of ‘keyLength’ shadows a member of ‘llvm::StringMapEntryStorage<std::pair<long unsigned int, std::array<unsigned int, 5> > >’ [-Wshadow]
77 | StringMapEntryStorage(size_t keyLength, InitTy &&… initVals)
| ~^~~
/usr/include/llvm-15/llvm/ADT/StringMapEntry.h:27:10: note: shadowed declaration is here
27 | size_t keyLength;
| ^~~~~~~~~

First question: What compiler are you using to build your project? The diagnostics you are reporting look like you’re using Clang as your build compiler; what version is it?

The diagnostics seem to be triggering on a common case where a data member and a constructor parameter use the same name. This is not actually ambiguous when used in an initializer list, but could be problematic in the body of the function.

class foo {
  void *Member;
  foo(void *Member) // param shadows member
    : Member(Member) // initializes data member with parameter
    { Member = Member; } // self-assignment of the parameter

I’d hope that Clang would be smart enough not to diagnose this case, but apparently not…