title: Clang: error: invalid use of non-static data member
body: <p>Is this gcc being overly nice and doing what the dev thinks it will do or is clang being overly fussy about something. Am I missing some subtle rule in the standard where clang is actually correct in complaining about this</p>
  
  <p>Or should I use the second bit of code which is basically the how offsetof works </p>
  
  <pre><code>[adrian@localhost ~]$ g++ -Wall -pedantic -ansi a.cc
  [adrian@localhost ~]$ a.out
  50
  [adrian@localhost ~]$ cat a.cc
  #include &lt;iostream&gt;
  
  struct Foo
  {
     char name[50];
  };
  
  int main(int argc, char *argv[])
  {
     std::cout &lt;&lt; sizeof(Foo::name) &lt;&lt; std::endl;
     return 0;
  }
  
  
  [adrian@localhost ~]$ clang++ a.cc
  a.cc:10:29: error: invalid use of non-static data member 'name'
     std::cout &lt;&lt; sizeof(Foo::name) &lt;&lt; std::endl;
                         ~~~~~^~~~
  1 error generated.
  [adrian@localhost ~]$ g++ -Wall -pedantic -ansi b.cc
  [adrian@localhost ~]$ a.out
  50
  [adrian@localhost ~]$ cat b.cc
  #include &lt;iostream&gt;
  
  struct Foo
  {
     char name[50];
  };
  
  int main(int argc, char *argv[])
  {
     std::cout &lt;&lt; sizeof(static_cast&lt;Foo*&gt;(0)-&gt;name) &lt;&lt; std::endl;
     return 0;
  }
  
  
  [adrian@localhost ~]$ clang++ b.cc
  [adrian@localhost ~]$ a.out
  50
  </code></pre>