[cfe-dev] how to modify clang to allow bolt-on member functions?

Csaba Raduly rcsaba at gmail.com
Sun Apr 21 01:51:11 PDT 2013

Hi Walter,

On Sat, Apr 20, 2013 at 5:51 PM, walter lynsdale  wrote:
> #include <iostream>
> struct Foo {
>     int    x;
>     void bar();
> };
> void Foo::bar() {//<<<<<< not declared in the class
>     std::cout<<x;
> }
> int main(int argc,const char** argv){
>     Foo    f;f.x=10;
>     f.bar();
> }
> Could anyone comment how difficult it would be to modify my own build of
> clang to allow this to compile. (and provide pointers on which areas of the
> source to look at)

I don't understand why you want to modify your compiler. This code
compiles fine with both g++ 4.5.3 and clang++ 3.3 (trunk 178973)

$ g++ -Wall -pedantic -W bolt-on.cpp
bolt-on.cpp:9:5: warning: unused parameter ‘argc’
bolt-on.cpp:9:5: warning: unused parameter ‘argv’

$ clang++ -Wall -pedantic -W bolt-on.cpp
bolt-on.cpp:9:14: warning: unused parameter 'argc' [-Wunused-parameter]
int main(int argc,const char** argv){
bolt-on.cpp:9:32: warning: unused parameter 'argv' [-Wunused-parameter]
int main(int argc,const char** argv){
2 warnings generated.

Note that Foo::bar _is_ declared in the class (the "void bar();" line
inside struct Foo declares a function Foo::bar).

GCS a+ e++ d- C++ ULS$ L+$ !E- W++ P+++$ w++$ tv+ b++ DI D++ 5++
The Tao of math: The numbers you can count are not the real numbers.
Life is complex, with real and imaginary parts.
"Ok, it boots. Which means it must be bug-free and perfect. " -- Linus Torvalds
"People disagree with me. I just ignore them." -- Linus Torvalds

More information about the cfe-dev mailing list