stb icon indicating copy to clipboard operation
stb copied to clipboard

[Suggestion] stb_vorbis: "declaration shadows a local variable" Clang errors

Open gtreshchev opened this issue 3 years ago • 6 comments
trafficstars

Describe the bug There are tons of errors related to declaration shadows a local variable like this one: error: declaration shadows a local variable [-Werror,-Wshadow] int z = get8_packet_raw(f);

To Reproduce Try to compile stb_vorbis using Clang 3.5 with the "-Wshadow" option.

I know it's easy to fix this by renaming some of the variables (like here)

Screenshot 2021-12-04 142509 Screenshot 2021-12-04 142459 Screenshot 2021-12-04 142536 Screenshot 2021-12-04 142521

gtreshchev avatar Dec 05 '21 08:12 gtreshchev

Why do you call this a bug? Block scope is a legit language feature: https://en.cppreference.com/w/c/language/scope From my perspective, it is your problem that you are using -Werror command line switch.

alxklk avatar Dec 06 '21 12:12 alxklk

Why do you call this a bug? Block scope is a legit language feature: https://en.cppreference.com/w/c/language/scope From my perspective, it is your problem that you are using -Werror command line switch.

I know that it is okay in C, but many modern compilers issue this as a warning or an error even without "-Wshadow" option. Remove of shadowing variables would be a silver bullet.

gtreshchev avatar Dec 06 '21 12:12 gtreshchev

but many modern compilers issue this as a warning or an error even without "-Wshadow" option.

If a compiler is unable to compile valid C code then that compiler is defective and you should file a bug report against it.

Also which "modern compiler" errors on shadowing by default?? That sounds like bullshit.

N-R-K avatar Sep 11 '22 16:09 N-R-K

@N-R-K This is a perfectly reasonable request.

Generally stb libraries try to compile without warnings with any reasonable set of warnings (not -Wall and definitely not -Wextra) to streamline the integration. In this particular cases -Wshadow combined with warnings-as-errors (which is perfectly reasonable to turn on as well) makes the file incompilable. I have no problem with the complaint, and I may fix it at some point and will certainly accept a PR that fixes it.

nothings avatar Sep 11 '22 16:09 nothings

@N-R-K This is a perfectly reasonable request.

Sure, I didn't mean to come off as dismissive of the issue.

I was more curious about which compiler errors out due to -Wshadow by default. Because that warning is typically something that user needs to explicitly enable since it's stylistic in nature.

N-R-K avatar Sep 12 '22 03:09 N-R-K

I don't know the answer to your question, but it's a known source of bugs (e.g. introducing an inner-scoped variable that's already being used for a different purpose inside the scope), not purely stylistic.

nothings avatar Sep 12 '22 04:09 nothings