title: problem with clang application
body: <p>I am building an application using clang libraries, I running to a
  problem, it will be very helpful if somebody can give some directions. </p>
  
  <p><code>#./a.out /home/nmathew/Desktop/algorithms/array.cpp</code> gives</p>
  
  <pre><code>In file included from /home/nmathew/Desktop/algorithms/array.cpp:1:
  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&amp;, const
  clang::FixItHint*, unsigned int, unsigned int, unsigned int, unsigned
  int, unsigned int): Assertion `LangOpts &amp;&amp; "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'
  Aborted (core dumped)
  </code></pre>
  
  <p>My Include search directories are below.<br /></p>
  
  <p><code>#include "..."</code> search starts here:<br />
  <code>#include &lt;...&gt;</code> search starts here:<br />
   /usr/include/linux<br />
   /usr/lib/gcc/i686-redhat-linux/4.4.3/include<br />
   /usr/include/c++/4.4.3<br />
   /usr/include/c++/4.4.3/backward<br />
   /usr/include/c++/4.4.3/i686-redhat-linux<br />
   /usr/local/include<br />
   /usr/include<br />
  End of search list.<br />
  <br />
  and char_traits.h is in /usr/include/c++/4.4.3/bits/, I am using
  Fedora 12   32bit system.<br />
  </p></p>
  
  <p>My code is listed below</p>
  
  <p>tut01_pp.cpp</p>
  
  <pre><code>#include "PPContext.h"
  
  int main(int argc, char *argv[])
  {
          if (argc != 2)
          {
                  return 0;
          }
  
          PPContext scope;
          scope.headers.PrintStats();
          const FileEntry *File = scope.fm.getFile(argv[1]);
  
          if(!File)
          {
                 return 0;
          }
  
          scope.sm.createMainFileID(File, SourceLocation());
          scope.pp-&gt;EnterMainSourceFile();
          IdentifierTable identitab(scope.lang);
          MinimalAction action(*(scope.pp));
          Parser parse(*(scope.pp), action);
          parse.ParseTranslationUnit();
          identitab.PrintStats();
  
          return 0;
  }
  </code></pre>
  
  <p>PPContext.h</p>
  
  <pre><code>#ifndef PP_CONTEXT
  #define PP_CONTEXT
  
  #include &lt;iostream&gt;
  #include &lt;string&gt;
  using namespace std;
  
  #include &lt;llvm/Support/raw_ostream.h&gt;
  
  #include &lt;clang/Basic/Diagnostic.h&gt;
  #include &lt;clang/Basic/TargetInfo.h&gt;
  #include &lt;clang/Basic/TargetOptions.h&gt;
  #include &lt;clang/Basic/FileManager.h&gt;
  #include &lt;clang/Basic/SourceManager.h&gt;
  #include &lt;clang/Lex/Preprocessor.h&gt;
  #include &lt;clang/Lex/HeaderSearch.h&gt;
  #include &lt;clang/Frontend/Utils.h&gt;
  #include &lt;clang/Frontend/TextDiagnosticPrinter.h&gt;
  #include &lt;clang/Frontend/DiagnosticOptions.h&gt;
  #include &lt;clang/Frontend/HeaderSearchOptions.h&gt;
  #include &lt;clang/Parse/Action.h&gt;
  #include &lt;clang/Parse/Parser.h&gt;
  #include "llvm/System/Host.h"
  using namespace clang;
  using namespace llvm;
  
  struct PPContext {
          PPContext():tdp(ost, options), diag(&amp;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
  </code></pre>
  
  <p>array.cpp</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include "array.hpp"
  
  using namespace std;
  
  
  
  template &lt;class gen&gt;
  ARRAY&lt;gen&gt;::ARRAY()
  {
   size = MAX;
   ptr = (gen (*)[MAX])new gen[size];
  }
  
  template &lt;class gen&gt;
  ARRAY&lt;gen&gt;::ARRAY(int array_size)
  {
   size = array_size;
   ptr = (gen (*)[])new gen[size];
  }
  
  template &lt;class gen&gt;
  ARRAY&lt;gen&gt;::~ARRAY()
  {
   delete (gen (*)[MAX])ptr;
  }
  
  template &lt;class gen&gt;
  int ARRAY&lt;gen&gt;::getsize()
  {
   return size;
  }
  
  template &lt;class gen&gt;
  ARRAY&lt;gen&gt;::ARRAY(const ARRAY &amp;orig)
  {
   ptr = (gen (*)[MAX])new gen[orig.size];
   memcpy(ptr, orig.ptr, sizeof(gen)*orig.size);
   size = orig.size;
  }
  
  template &lt;class gen&gt;
  gen&amp; ARRAY&lt;gen&gt;::operator [](unsigned int index)
  {
   return *ptr[index];
  }
  
  int main(void)
  {
   ARRAY &lt;int&gt; intarray;
   intarray[8] = 16;
   return 0;
  }
  </code></pre>