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 9134607
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T08:41:36+00:00 2026-06-17T08:41:36+00:00

Summary : I have a code snippet that compiles fine with g++ but not

  • 0

Summary:
I have a code snippet that compiles fine with g++ but not with clang.

Details:

I have a project that compiles fine with g++ but when compiling with clang I get an error about error: use of non-static data member. I tried to create a small test case that would demonstrate the problem, but for the small test case g++ gave the same error as clang.

I’ve posted a 236 line file to pastebin that demonstrates the problem:
http://pastebin.com/DGnfxmYe

When compiled with g++ 4.6.3 this works fine. But when compiled with clang 3.2 I get the following error messages:

myhashmap.hpp:169:29: error: use of non-static data member 'num_bins' of 'MyHashMap' from nested type 'iterator'
          for (_index++; (_index < num_bins) && (bins[_index] == NULL); _index++)
                                   ^~~~~~~~
myhashmap.hpp:169:43: error: use of non-static data member 'bins' of 'MyHashMap' from nested type 'iterator'
          for (_index++; (_index < num_bins) && (bins[_index] == NULL); _index++)
                                                 ^~~~
myhashmap.hpp:171:17: error: use of non-static data member 'num_bins' of 'MyHashMap' from nested type 'iterator'
          if (_index < num_bins) {
                       ^~~~~~~~
myhashmap.hpp:172:17: error: use of non-static data member 'bins' of 'MyHashMap' from nested type 'iterator'
            _theNode = bins[_index];
                       ^~~~

Looking at the code, it makes sense to me why clang is giving these error messages. What I don’t understand is why g++ compiled the code correctly in the first place. I did not write this code but I would like to get it to compile cleanly with clang. So I’m trying to understand exactly what it is doing. And I would be interested in understanding why it compiles with g++ but not with clang. Does g++ interpret the c++ standard differently, or is there some g++ extension that the code is taking advantage of?

  • 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-06-17T08:41:37+00:00Added an answer on June 17, 2026 at 8:41 am

    It fails with GCC 4.8 (prerelease) so I assume it’s a bug that’s been fixed. I can’t find a corresponding bug report though.

    To fix the code I think you’ll need add an int _num_bins member to the iterator and pass the cotnainer’s num_bins to the iterator constructor in begin() and end(), so it’s stored in each iterator object.


    (Additionally, don’t write (void) for a function taking no arguments, that’s an abomination. In C++ a function taking no arguments is written ())

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

Sidebar

Related Questions

I have some code which makes use of Extension Methods, but compiles under .NET
I have the following code snippet I'm trying to get the text from: <span
Summary I have looked over the code the SpiderMonkey 'shell' application uses to create
I have two identical byte arrays in the following segment of code: /// <summary>
I have a performance bottleneck on a DataView.Sort. The code is below. /// <summary>
--Summary (shortened)-- I have a controller that loads a profile object from the corresponding
I have the following code snippet. public static void main(String[] args) { short a
I currently have this code: /// <summary> /// This is an ineffecient method of
Summary I have written a process monitor command-line application that takes as parameters: The
Summary : I have a project using GNU Autotools. I have a pot file.

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.