Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 339611
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T10:32:21+00:00 2026-05-12T10:32:21+00:00

Folks, I really like the -Wshadow option since it helps to spot some possible

  • 0

Folks, I really like the -Wshadow option since it helps to spot some possible problematic pieces of code. I want to use it in a really large project but I can’t since it’s too strict. For example it throws a warning for the following case:

struct Foo
{
  Foo(int info) : info_(info) {} //shadow warning is here
  void info(){ ... }
  int info_;
};

gcc throws a warning about “int info” variable shadowing “void info” method in constructor which is… well, not really a useful warning for me.

What I really care about is cases such as the following:

  int i = 0;
  for(int j=0;j<10;++j)
  {
    int i = j; //local scope variable "int i" shadows outer scope variable
    ++i;
  }

Is it possible to make gcc warn about these cases only?

  • 1 1 Answer
  • 1 View
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T10:32:21+00:00Added an answer on May 12, 2026 at 10:32 am

    For external libraries you can try to specify their include path with -isystem instead of -I, this will cause gcc to stop reporting warnings in them most of the time.

    When the warning only pops up in a few limited cases you can work around it with:

    #pragma GCC diagnostic ignored "-Wshadow"

    For the rest of the cases refactoring the code or doing the grep trick Peter mentioned seem to be the only options.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I don't believe in a Silver Bullet, but I really like to use sequences
I'd really like some help with the following MySQL / PHP problem (maybe bug?)
Folks, I'd like to create some T4 templates for generating class files (about 7
Dear folks, in order to remove some really crazy /%A/%E\%FD occuring in the urls
Hello once again stackoverflow folks, this is really hard and it's been torturing my
Folks I am surprised to see my code working, that I dont have any
Folks I have a sealed class as follows. I want to extend this sealed
Folks, I want to know how to fill the gap between the server-side and
I'm turning to you folks for answers because this really blows my mind... Let
folks. I would really appreciate to have your help on the following question: In

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.