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

  • SEARCH
  • Home
  • 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 7406917
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T05:37:47+00:00 2026-05-29T05:37:47+00:00

I am getting a -Wunused-but-set-variable warning with GCC v4.6 with the code below: for

  • 0

I am getting a -Wunused-but-set-variable warning with GCC v4.6 with the code below:

for ( auto i : f.vertexIndices ) {
    Sy_MatrixFuzzyHashable< Vector3f > wrapper( cp );
    if ( !vMapper.contains( wrapper ) ) {
        mesh.vertexNormals() << cp;
        i.normal = mesh.vertexNormals().size() - 1;
     } else {
        i.normal = vMapper.value( wrapper );
     }
}

The warning specifically is:

warning: variable 'i' set but not used [-Wunused-but-set-variable]

The warning would make sense if i was a copy of an element, but since vertexIndices is a QList object (an STL-compliant Qt container class) the range-based for loop should call the begin() and end() iterator getters, which will always return a non-const iterator (as long as the container is non-const – which it is).

I can’t currently test if it is working as I think it should because I’m changing my code base to take advantage of the new C++11 features, so nothing compiles yet. But I was hoping someone could tell me if this warning is is nonsense, or if I have misunderstood auto and range-based for loops…

  • 1 1 Answer
  • 0 Views
  • 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-29T05:37:48+00:00Added an answer on May 29, 2026 at 5:37 am

    I think the issue is that your for loop, as written like this:

    for ( auto i : f.vertexIndices ) 
    

    is getting back a copy of the stored vertex, not a reference to it. The compiler warning here says that you’re then setting the value of i but not reading it because you’re modifying the temporary copy rather than the stored vertex.

    If you change it to

    for ( auto& i : f.vertexIndices ) 
    

    then this problem should go away, since you’re actually modifying the vertices stored internally.

    Hope this helps!

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

Sidebar

Related Questions

Getting the above error in following code. How to rectify it. Thanks. Please look
Getting this error: 2009-09-03 12:44:02.307 xcodebuild[307:10b] warning: compiler 'com.apple.compilers.llvm.clang.1_0.analyzer' is based on missing compiler
Getting this. Site works fine locally, but up on production server I get this
Getting warning message that Duplicate protocol definition of ModalViewDelegate is ignored Defined protocol in
Getting through some practice exam papers but in regards to the relational algebra I'm
Getting the following error: "Warning: Cannot modify header information - headers already sent by
getting an Warning: Invalid argument supplied for foreach() in /home/maxer/domains/x/public_html/x/items.php on line 41 line
Getting data from a database table to an object in code has always seemed
Getting the following error, which I understand and have seen before. But one thing
Getting an error with my code found HERE ... Which is a culmination of

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.