Rocksdb: Clang 8.0 (RC) finds shadow enum values

Created on 5 Feb 2019  路  11Comments  路  Source: facebook/rocksdb

With clang 8.0 RC1 arm/musl I see this error

In file included from /mnt/a/yoe/build/tmp/work/cortexa5t2hf-neon-vfpv4-yoe-linux-musleabi/rocksdb/5.18.2-r0/git/db/builder.cc:19:
/mnt/a/yoe/build/tmp/work/cortexa5t2hf-neon-vfpv4-yoe-linux-musleabi/rocksdb/5.18.2-r0/git/db/internal_stats.h:112:5: error: declaration shadows a variable in namespace 'rocksdb' [-Werror,-Wshadow]
    WAL_FILE_BYTES,
    ^
/mnt/a/yoe/build/tmp/work/cortexa5t2hf-neon-vfpv4-yoe-linux-musleabi/rocksdb/5.18.2-r0/git/include/rocksdb/statistics.h:191:3: note: previous declaration is here
  WAL_FILE_BYTES,   // Number of bytes written to WAL
  ^
In file included from /mnt/a/yoe/build/tmp/work/cortexa5t2hf-neon-vfpv4-yoe-linux-musleabi/rocksdb/5.18.2-r0/git/db/builder.cc:19:
/mnt/a/yoe/build/tmp/work/cortexa5t2hf-neon-vfpv4-yoe-linux-musleabi/rocksdb/5.18.2-r0/git/db/internal_stats.h:113:5: error: declaration shadows a variable in namespace 'rocksdb' [-Werror,-Wshadow]
    WAL_FILE_SYNCED,
    ^
/mnt/a/yoe/build/tmp/work/cortexa5t2hf-neon-vfpv4-yoe-linux-musleabi/rocksdb/5.18.2-r0/git/include/rocksdb/statistics.h:190:3: note: previous declaration is here
  WAL_FILE_SYNCED,  // Number of times WAL sync is done
  ^
In file included from /mnt/a/yoe/build/tmp/work/cortexa5t2hf-neon-vfpv4-yoe-linux-musleabi/rocksdb/5.18.2-r0/git/db/builder.cc:19:
/mnt/a/yoe/build/tmp/work/cortexa5t2hf-neon-vfpv4-yoe-linux-musleabi/rocksdb/5.18.2-r0/git/db/internal_stats.h:114:5: error: declaration shadows a variable in namespace 'rocksdb' [-Werror,-Wshadow]
    BYTES_WRITTEN,
    ^
/mnt/a/yoe/build/tmp/work/cortexa5t2hf-neon-vfpv4-yoe-linux-musleabi/rocksdb/5.18.2-r0/git/include/rocksdb/statistics.h:126:3: note: previous declaration is here
  BYTES_WRITTEN,
  ^
In file included from /mnt/a/yoe/build/tmp/work/cortexa5t2hf-neon-vfpv4-yoe-linux-musleabi/rocksdb/5.18.2-r0/git/db/builder.cc:19:
/mnt/a/yoe/build/tmp/work/cortexa5t2hf-neon-vfpv4-yoe-linux-musleabi/rocksdb/5.18.2-r0/git/db/internal_stats.h:115:5: error: declaration shadows a variable in namespace 'rocksdb' [-Werror,-Wshadow]
    NUMBER_KEYS_WRITTEN,
    ^
/mnt/a/yoe/build/tmp/work/cortexa5t2hf-neon-vfpv4-yoe-linux-musleabi/rocksdb/5.18.2-r0/git/include/rocksdb/statistics.h:119:3: note: previous declaration is here
  NUMBER_KEYS_WRITTEN,
  ^
In file included from /mnt/a/yoe/build/tmp/work/cortexa5t2hf-neon-vfpv4-yoe-linux-musleabi/rocksdb/5.18.2-r0/git/db/builder.cc:19:
/mnt/a/yoe/build/tmp/work/cortexa5t2hf-neon-vfpv4-yoe-linux-musleabi/rocksdb/5.18.2-r0/git/db/internal_stats.h:116:5: error: declaration shadows a variable in namespace 'rocksdb' [-Werror,-Wshadow]
    WRITE_DONE_BY_OTHER,
    ^
/mnt/a/yoe/build/tmp/work/cortexa5t2hf-neon-vfpv4-yoe-linux-musleabi/rocksdb/5.18.2-r0/git/include/rocksdb/statistics.h:196:3: note: previous declaration is here
  WRITE_DONE_BY_OTHER,  // Equivalent to writes done for others
  ^
In file included from /mnt/a/yoe/build/tmp/work/cortexa5t2hf-neon-vfpv4-yoe-linux-musleabi/rocksdb/5.18.2-r0/git/db/builder.cc:19:
/mnt/a/yoe/build/tmp/work/cortexa5t2hf-neon-vfpv4-yoe-linux-musleabi/rocksdb/5.18.2-r0/git/db/internal_stats.h:117:5: error: declaration shadows a variable in namespace 'rocksdb' [-Werror,-Wshadow]
    WRITE_DONE_BY_SELF,
    ^
/mnt/a/yoe/build/tmp/work/cortexa5t2hf-neon-vfpv4-yoe-linux-musleabi/rocksdb/5.18.2-r0/git/include/rocksdb/statistics.h:195:3: note: previous declaration is here
  WRITE_DONE_BY_SELF,
  ^
In file included from /mnt/a/yoe/build/tmp/work/cortexa5t2hf-neon-vfpv4-yoe-linux-musleabi/rocksdb/5.18.2-r0/git/db/builder.cc:19:
/mnt/a/yoe/build/tmp/work/cortexa5t2hf-neon-vfpv4-yoe-linux-musleabi/rocksdb/5.18.2-r0/git/db/internal_stats.h:118:5: error: declaration shadows a variable in namespace 'rocksdb' [-Werror,-Wshadow]
    WRITE_WITH_WAL,
    ^
/mnt/a/yoe/build/tmp/work/cortexa5t2hf-neon-vfpv4-yoe-linux-musleabi/rocksdb/5.18.2-r0/git/include/rocksdb/statistics.h:198:3: note: previous declaration is here
  WRITE_WITH_WAL,       // Number of Write calls that request WAL
  ^
7 errors generated.
up-for-grabs

Most helpful comment

It looks like that some enums in InternalDBStatsType and Tickers have same name.

./db/internal_stats.h

enum InternalDBStatsType {
   WAL_FILE_BYTES,
   WAL_FILE_SYNCED,
   BYTES_WRITTEN,
   NUMBER_KEYS_WRITTEN,
   WRITE_DONE_BY_OTHER,
   WRITE_DONE_BY_SELF,
   WRITE_WITH_WAL,
   WRITE_STALL_MICROS,
   INTERNAL_DB_STATS_ENUM_MAX,
};

./include/rocksdb/statistics.h

enum Tickers : uint32_t {
// .....
  WAL_FILE_BYTES,   // Number of bytes written to WAL
// .....
}

Is there any suggestion for fixing this warning?
Just change the name of enums in InternalDBStatsType (such as WAL_FILE_BYTES to INTERNAL_WAL_FILE_BYTES) or avoid using enum here?

All 11 comments

We are not building with clang 8.0 yet, so can't comment on the error or the right fix for this. But would you like to contribute the fix?

I do not have solution for it yet and time is also a crunch, I will add -Wno-error=shadow to make it toe the line for now.

It looks like that some enums in InternalDBStatsType and Tickers have same name.

./db/internal_stats.h

enum InternalDBStatsType {
   WAL_FILE_BYTES,
   WAL_FILE_SYNCED,
   BYTES_WRITTEN,
   NUMBER_KEYS_WRITTEN,
   WRITE_DONE_BY_OTHER,
   WRITE_DONE_BY_SELF,
   WRITE_WITH_WAL,
   WRITE_STALL_MICROS,
   INTERNAL_DB_STATS_ENUM_MAX,
};

./include/rocksdb/statistics.h

enum Tickers : uint32_t {
// .....
  WAL_FILE_BYTES,   // Number of bytes written to WAL
// .....
}

Is there any suggestion for fixing this warning?
Just change the name of enums in InternalDBStatsType (such as WAL_FILE_BYTES to INTERNAL_WAL_FILE_BYTES) or avoid using enum here?

The change is due to more strict warnings in Clang 8, as detailed here:

https://bugs.llvm.org/show_bug.cgi?id=24718

https://reviews.llvm.org/rG20ea72476c31f96ee526b06f050aef05956be9fd

I do not have solution for it yet and time is also a crunch, I will add -Wno-error=shadow to make it toe the line for now.

where do you add it? I tried passing via export RUSTFLAGS="-Wno-error=shadow" ang get following error: error[E0602]: unknown lint: no_error=shadow
|
= note: requested on the command line with -W no_error=shadow

-Wno-error=shadow is a flag for the C++ compiler, not the rust compiler. I don't think it has anything to do with RUSTFLAGS.

@sagar0 the issue repros with 8.0.0 release, not just RC.

This error also occurs if using android ndk r20 which supports only the clang toolchain.

Hi, this fix probably has invalid formatting and few other issues, but it seems to be compiling,
(I haven't checked ROCKSDB_LITE ifdef branch though).

The fix consists of fairly simple changes:

  1. promotes InternalCFStatsType and InternalDBStatsType to top rocksdb namespace
  2. turns both enums into enum classes
  3. fixes usage

(this is on top of 6.2.fb branch, but it should be fairly trivial to rebase if needed)

https://github.com/nemtech/rocksdb/commit/f413c0b454965409f727694c02e5349e56dea257

Is it fixed?

I think #5779 should've fixed it.

Was this page helpful?
0 / 5 - 0 ratings