Errors building clang with FSF gcc trunk

I'm trying to build clang with gcc trunk on Mac OS X:
gcc version 4.4.0 20080310 (experimental) [trunk revision 133080] (GCC)

I'm not sure if it's more strict, or the libstdc++ headers have changed, or what, but the following errors occur:
llvm[1]: Compiling Diagnostic.cpp for Debug-Asserts build
Diagnostic.cpp: In constructor 'clang::Diagnostic::Diagnostic(clang::DiagnosticClient&)':
Diagnostic.cpp:114: error: 'memset' was not declared in this scope
...
llvm[1]: Compiling ScratchBuffer.cpp for Debug-Asserts build
ScratchBuffer.cpp: In member function 'clang::SourceLocation clang::ScratchBuffer::getToken(const char*, unsigned int)':
ScratchBuffer.cpp:38: error: 'memcpy' was not declared in this scope
...
CFG.cpp: In member function 'void clang::CFG::viewCFG() const':
CFG.cpp:1457: error: 'cerr' is not a member of 'std'
...
GRSimpleVals.cpp:33: error: explicit template specialization cannot have a storage class
GRSimpleVals.cpp:55: error: explicit template specialization cannot have a storage class
...
llvm[1]: Compiling Rewriter.cpp for Debug-Asserts build
In file included from /Volumes/HD/ltmp/ssen/llvm/tools/clang/Rewrite/../include/clang/Rewrite/Rewriter.h:19,
                  from Rewriter.cpp:15:
/Volumes/HD/ltmp/ssen/llvm/tools/clang/Rewrite/../include/clang/Rewrite/RewriteRope.h: In member function 'clang::RopePiece clang::RewriteRope::MakeRopeString(const char*, const char*)':
/Volumes/HD/ltmp/ssen/llvm/tools/clang/Rewrite/../include/clang/Rewrite/RewriteRope.h:243: error: 'memcpy' was not declared in this scope
/Volumes/HD/ltmp/ssen/llvm/tools/clang/Rewrite/../include/clang/Rewrite/RewriteRope.h:255: error: 'memcpy' was not declared in this scope
/Volumes/HD/ltmp/ssen/llvm/tools/clang/Rewrite/../include/clang/Rewrite/RewriteRope.h:264: error: 'memcpy' was not declared in this scope
In file included from Rewriter.cpp:16:
...
llvm[1]: Compiling SerializationTest.cpp for Debug-Asserts build
SerializationTest.cpp: In destructor 'virtual<unnamed>::SerializationTest::~SerializationTest()':
SerializationTest.cpp:167: error: 'strlen' was not declared in this scope

Attached is a patch for all but the GRSimpleVals.cpp issue. Removing "static" fixes it, but I'm not really sure what the error is really trying to convey. For the other cases, the source files do indeed use those functions without explicitly including <string.h> or <iostream>, and it seems bad to rely on side effects of other headers, even if it used to work before.

clang.gcc-trunk.patch (1.8 KB)

I'm not sure if it's more strict, or the libstdc++ headers have changed, or what, but the following errors occur:

I think that they did a cleanup of the libstdc++ headers to make them #include less. I agree with you that the clang source should include hte headers it needs, not relying on an artifact of the libstdc++ implementation.

...
GRSimpleVals.cpp:33: error: explicit template specialization cannot have a storage class
GRSimpleVals.cpp:55: error: explicit template specialization cannot have a storage class
...

Attached is a patch for all but the GRSimpleVals.cpp issue. Removing "static" fixes it, but I'm not really sure what the error is really trying to convey.

I think your patch is right, thanks.

For the other cases, the source files do indeed use those functions without explicitly including <string.h> or <iostream>, and it seems bad to rely on side effects of other headers, even if it used to work before.

I applied both changes. The only change I made was to turn <string.h> -> <cstring>, which is the functionally equivalent but more C++'y version of the header.

http://lists.cs.uiuc.edu/pipermail/cfe-commits/Week-of-Mon-20080310/004642.html
http://lists.cs.uiuc.edu/pipermail/cfe-commits/Week-of-Mon-20080310/004643.html

Thanks Shantonu!

-Chris

I think that they did a cleanup of the libstdc++ headers to make them
#include less. I agree with you that the clang source should include
hte headers it needs, not relying on an artifact of the libstdc++
implementation.

Definitely. I've cleaned LLVM, but haven't touched clang :slight_smile:

Cool :slight_smile:

You have exposed my total lack of familiarity with C++.

Shantonu Sen
ssen@apple.com