On Sun, Jun 20, 2010 at 7:13 PM, Jonathan Wakely <jwakely.gcc@xxxxxxxxx> wrote: > On 20 June 2010 10:14, Paolo Carlini <paolo.carlini@xxxxxxxxxx> wrote: >> On 06/20/2010 07:33 AM, Nobin Mathew wrote: >>> Please help even if this is a dump question, I am new to the land of c++. >>> >> To be clear, the libstdc++ mailing list is about the *development* of >> the library, is not a generic help list whatsoever. > > Which means cross-posting to libstdc++ and gcc-help is not appropriate. Sorry for the trouble, this was not intentional. > > It's possible that there is a bug in the libstdc++ headers which is > picked up by clang and not by g++, but since you didn't post a > complete testcase that case be inspected, there's no way to know. pasted below > > If you think there's a bug, please provide a complete testcase > demonstrating it, either on the libstdc++ list or following these > instructions: http://gcc.gnu.org/bugs/ > > If you have a basic question about using gcc please follow-up on the > gcc-help list. > >>> iosfwd uses uses char_traits but bits/char_traits.h is included after >>> iosfwd in ios header > > That shouldn't matter, char_traits is declared in bits/stringfwd.h not > bits/char_traits.h > #./a.out /home/nmathew/Desktop/algorithms/array.cpp gives #include <...> search starts here: /usr/include/linux /usr/lib/gcc/i686-redhat-linux/4.4.3/include /usr/include/c++/4.4.3 /usr/include/c++/4.4.3/backward /usr/include/c++/4.4.3/i686-redhat-linux /usr/local/include /usr/include End of search list. *** HeaderSearch Stats: 0 files tracked. 0 #import/#pragma once files. 0 included exactly once. 0 max times a file is included. 0 #include/#include_next/#import. 0 #includes skipped due to the multi-include optimization. 0 framework lookups. 0 subframework lookups. *** Preprocessor Stats: 0 directives found: 0 #define. 0 #undef. #include/#include_next/#import: 2 source files entered. 0 max include stack depth 0 #if/#ifndef/#ifdef. 0 #else/#elif. 0 #endif. 0 #pragma. 0 #if/#ifndef#ifdef regions skipped 0/0/0 obj/fn/builtin macros expanded, 0 on the fast path. 0 token paste (##) operations performed, 0 on the fast path. In file included from /home/nmathew/Desktop/algorithms/array.cpp:2: In file included from /usr/include/c++/4.4.3/iostream:39: In file included from /usr/include/c++/4.4.3/ostream:39: In file included from /usr/include/c++/4.4.3/ios:38: In file included from /usr/include/c++/4.4.3/iosfwd:40: /usr/include/c++/4.4.3/bits/stringfwd.h:49:48: error: unknown type name 'char_traits' a.out: TextDiagnosticPrinter.cpp:293: void clang::TextDiagnosticPrinter::EmitCaretDiagnostic(clang::SourceLocation, clang::SourceRange*, unsigned int, const clang::SourceManager&, const clang::FixItHint*, unsigned int, unsigned int, unsigned int, unsigned int, unsigned int): Assertion `LangOpts && "Unexpected diagnostic outside source file processing"' failed. Stack dump: 0. /usr/include/c++/4.4.3/bits/stringfwd.h:49:48: current parser token 'char_traits' 1. /usr/include/c++/4.4.3/bits/stringfwd.h:41:1 <Spelling=/usr/include/c++/4.4.3/i686-redhat-linux/bits/c++config.h:114:38>: parsing namespace Aborted (core dumped) I think in stringfwd.h _GLIBCXX_BEGIN_NAMESPACE(std) is parsed for the first time. My complete program is below. File tut01_pp.cpp #include "PPContext.h" int main(int argc, char *argv[]) { if (argc != 2) { cerr << "No File input " << endl; return 0; } PPContext scope; scope.headers.PrintStats(); const FileEntry *File = scope.fm.getFile(argv[1]); if(!File) { cerr << "File Open Failed\t" << argv[1] << endl; return 0; } scope.sm.createMainFileID(File, SourceLocation()); scope.pp->EnterMainSourceFile(); IdentifierTable identitab(scope.lang); MinimalAction action(*(scope.pp)); Parser parse(*(scope.pp), action); parse.ParseTranslationUnit(); identitab.PrintStats(); return 0; } File PPContext.h #ifndef PP_CONTEXT #define PP_CONTEXT #include <iostream> #include <string> using namespace std; #include <llvm/Support/raw_ostream.h> #include <clang/Basic/Diagnostic.h> #include <clang/Basic/TargetInfo.h> #include <clang/Basic/TargetOptions.h> #include <clang/Basic/FileManager.h> #include <clang/Basic/SourceManager.h> #include <clang/Lex/Preprocessor.h> #include <clang/Lex/HeaderSearch.h> #include <clang/Frontend/Utils.h> #include <clang/Frontend/TextDiagnosticPrinter.h> #include <clang/Frontend/DiagnosticOptions.h> #include <clang/Frontend/HeaderSearchOptions.h> #include <clang/Parse/Action.h> #include <clang/Parse/Parser.h> #include "llvm/System/Host.h" using namespace clang; using namespace llvm; struct PPContext { PPContext():tdp(ost, options), diag(&tdp), sm(diag), headers(fm) { TargetOptions target_options; target_options.Triple = sys::getHostTriple(); target_options.CXXABI = "itanium"; target = TargetInfo::CreateTargetInfo(diag, target_options); lang.CPlusPlus = 1; pp = new Preprocessor(diag, lang, *target, sm, headers); headeropts.EnvIncPath = "/usr/include/linux"; headeropts.CXXEnvIncPath = "/usr/lib/gcc/i686-redhat-linux/4.4.3/include/"; headeropts.Verbose = 1; ApplyHeaderSearchOptions(headers, headeropts, lang, llvm::Triple(target_options.Triple)); }; ~PPContext() { delete pp; delete target; }; llvm::raw_stdout_ostream ost; const DiagnosticOptions options; TextDiagnosticPrinter tdp; Diagnostic diag; LangOptions lang; SourceManager sm; FileManager fm; HeaderSearch headers; TargetInfo *target; Preprocessor *pp; HeaderSearchOptions headeropts; }; #endif //#ifndef PP_CONTEXT File array.cpp #include <iostream> #include "array.h" using namespace std; template <class gen> ARRAY<gen>::ARRAY() { size = MAX; ptr = (gen (*)[MAX])new gen[size]; } template <class gen> ARRAY<gen>::ARRAY(int array_size) { size = array_size; ptr = (gen (*)[])new gen[size]; } template <class gen> ARRAY<gen>::~ARRAY() { delete (gen (*)[MAX])ptr; } template <class gen> int ARRAY<gen>::getsize() { return size; } template <class gen> ARRAY<gen>::ARRAY(const ARRAY &orig) { ptr = (gen (*)[MAX])new gen[orig.size]; memcpy(ptr, orig.ptr, sizeof(gen)*orig.size); size = orig.size; } template <class gen> gen& ARRAY<gen>::operator [](unsigned int index) { return *ptr[index]; } int main(void) { ARRAY <int> intarray; intarray[8] = 16; return 0; } File array.h #define MAX 10 template <class gen> class ARRAY { public: ARRAY(); ARRAY(int array_size); ~ARRAY(); ARRAY(const ARRAY &orig); //Copy constructor gen& operator [] (unsigned int index); int getsize(void); private: int size; gen (*ptr)[MAX]; }; [nmathew@Alchemist cppscope]$ gcc -v Using built-in specs. Target: i686-redhat-linux Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-bootstrap --enable-shared --enable-threads=posix --enable-checking=release --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-languages=c,c++,objc,obj-c++,java,fortran,ada --enable-java-awt=gtk --disable-dssi --enable-plugin --with-java-home=/usr/lib/jvm/java-1.5.0-gcj-1.5.0.0/jre --enable-libgcj-multifile --enable-java-maintainer-mode --with-ecj-jar=/usr/share/java/eclipse-ecj.jar --disable-libjava-multilib --with-ppl --with-cloog --with-tune=generic --with-arch=i686 --build=i686-redhat-linux Thread model: posix gcc version 4.4.3 20100127 (Red Hat 4.4.3-4) (GCC) [nmathew@Alchemist cppscope]$ Thanks Nobin