Change:
In Nixpkgs 17.09, 3.9 cannot find libstdc++ headers: This does work correctly with Clang 4.0 in 17.09, or Clang 3.9 in 17.03. Setting shows that the cc-wrapper is not adding the appropriate flags pointing to libstdc++ in gcc. See above. System: NixOS 17.03 Nix version: 1.12pre Nixpkgs version: 17.09beta285. Sandboxing enabled: no
According to git-bisect, one of the following commits is causing the issue (all by
Hmm, was supposed to have fixed this, but I guess only fixed 4.0. any idea?
Really thought I already applied those changes to the other versions, must have forgotten to push or something.
Ah I see now---I should have noticed when reviewing that. While we're at it, maybe we should inject it in cc-wrapper instead of stdenv? This mirrors and keeps slimmer.

Discussion:
<del> { newScope, stdenv, cmake, libxml2, python2, isl, fetchurl, overrideCC, wrapCC, ccWrapperFun }: </del> <ins> { newScope, stdenv, libstdcxxHook, cmake, libxml2, python2, isl, fetchurl , overrideCC, wrapCC, ccWrapperFun, darwin }: </ins> let callPackage = newScope (self // { inherit stdenv cmake libxml2 python2 isl version fetch; });

inherit clang-tools-extra_src stdenv; }; <del> clang = wrapCC self.clang-unwrapped; </del> <ins> clang = if stdenv.cc.isGNU then self.libstdcxxClang else self.libcxxClang; libstdcxxClang = ccWrapperFun { cc = self.clang-unwrapped; /* FIXME is this right? */ inherit (stdenv.cc) libc nativeTools nativeLibc; extraPackages = [ libstdcxxHook ]; }; </ins> libcxxClang = ccWrapperFun { cc = self.clang-unwrapped; <del> isClang = true; inherit (self) stdenv; </del> /* FIXME is this right? */ inherit (stdenv.cc) libc nativeTools nativeLibc; extraPackages = [ self.libcxx self.libcxxabi ]; }; <del> stdenv = overrideCC stdenv self.clang; </del> <ins> stdenv = stdenv.override (drv: { allowedRequisites = null; cc = self.clang; # Don't include the libc++ and libc++abi from the original stdenv. extraBuildInputs = stdenv.lib.optional stdenv.isDarwin darwin.CF; }); </ins> <del> libcxxStdenv = overrideCC stdenv self.libcxxClang; </del> <ins> libcxxStdenv = stdenv.override (drv: { allowedRequisites = null; cc = self.libcxxClang; # Don't include the libc++ and libc++abi from the original stdenv. extraBuildInputs = stdenv.lib.optional stdenv.isDarwin darwin.CF; }); </ins> lldb = callPackage ./lldb.nix {};

<del> { newScope, stdenv, isl, fetchurl, overrideCC, wrapCC, ccWrapperFun }: </del> <ins> { newScope, stdenv, libstdcxxHook, isl, fetchurl, overrideCC, wrapCC, ccWrapperFun, darwin }: </ins> let callPackage = newScope (self // { inherit stdenv isl version fetch; });

<del> { newScope, stdenv, isl, fetchurl, overrideCC, wrapCC, darwin, ccWrapperFun }: </del> <ins> { newScope, stdenv, libstdcxxHook, isl, fetchurl, overrideCC, wrapCC, ccWrapperFun, darwin }: </ins> let callPackage = newScope (self // { inherit stdenv isl version fetch; });

inherit clang-tools-extra_src stdenv; }; <del> clang = wrapCC self.clang-unwrapped; </del> <ins> clang = if stdenv.cc.isGNU then self.libstdcxxClang else self.libcxxClang; libstdcxxClang = ccWrapperFun { cc = self.clang-unwrapped; /* FIXME is this right? */ inherit (stdenv.cc) libc nativeTools nativeLibc; extraPackages = [ libstdcxxHook ]; }; </ins> libcxxClang = ccWrapperFun { cc = self.clang-unwrapped; <del> isClang = true; inherit (self) stdenv; </del> /* FIXME is this right? */ inherit (stdenv.cc) libc nativeTools nativeLibc; extraPackages = [ self.libcxx self.libcxxabi ]; }; <del> stdenv = overrideCC stdenv self.clang; libcxxStdenv = overrideCC stdenv self.libcxxClang; </del> <ins> stdenv = stdenv.override (drv: { allowedRequisites = null; cc = self.clang; # Don't include the libc++ and libc++abi from the original stdenv. extraBuildInputs = stdenv.lib.optional stdenv.isDarwin darwin.CF; }); libcxxStdenv = stdenv.override (drv: { allowedRequisites = null; cc = self.libcxxClang; # Don't include the libc++ and libc++abi from the original stdenv. extraBuildInputs = stdenv.lib.optional stdenv.isDarwin darwin.CF; }); </ins> lldb = callPackage ./lldb.nix {};

llvm-manpages = lowPrio self.llvm.man; clang-manpages = lowPrio self.clang-unwrapped.man; <del> clang = wrapCC self.clang-unwrapped; </del> <ins> clang = if stdenv.cc.isGNU then self.libstdcxxClang else self.libcxxClang; </ins> <del> openmp = callPackage ./openmp.nix {}; </del> <ins> libstdcxxClang = ccWrapperFun { cc = self.clang-unwrapped; /* FIXME is this right? */ inherit (stdenv.cc) libc nativeTools nativeLibc; extraPackages = [ libstdcxxHook ]; }; </ins> libcxxClang = ccWrapperFun { cc = self.clang-unwrapped; <del> isClang = true; inherit (self) stdenv; </del> /* FIXME is this right? */ inherit (stdenv.cc) libc nativeTools nativeLibc; extraPackages = [ self.libcxx self.libcxxabi ];

stdenv = stdenv.override (drv: { allowedRequisites = null; cc = self.clang; <del> # Use the gcc libstdc++ when targeting linux. extraBuildInputs = if stdenv.cc.isGNU then [ libstdcxxHook ] else drv.extraBuildInputs; </del> <ins> # Don't include the libc++ and libc++abi from the original stdenv. extraBuildInputs = stdenv.lib.optional stdenv.isDarwin darwin.CF; </ins> }); <del> libcxxStdenv = overrideCC stdenv self.libcxxClang; </del> <ins> libcxxStdenv = stdenv.override (drv: { allowedRequisites = null; cc = self.libcxxClang; # Don't include the libc++ and libc++abi from the original stdenv. extraBuildInputs = stdenv.lib.optional stdenv.isDarwin darwin.CF; }); </ins> lld = callPackage ./lld.nix {};

libcxx = callPackage ./libc++ {}; libcxxabi = callPackage ./libc++abi.nix {}; <ins> openmp = callPackage ./openmp.nix {}; </ins> }; in self

#Use this instead of stdenv to build with clang clangStdenv = if stdenv.isDarwin then stdenv else lowPrio llvmPackages.stdenv; clang-sierraHack-stdenv = overrideCC stdenv clang-sierraHack; <del> libcxxStdenv = lowPrio llvmPackages.libcxxStdenv; </del> <ins> libcxxStdenv = if stdenv.isDarwin then stdenv else lowPrio llvmPackages.libcxxStdenv; </ins> clean = callPackage ../development/compilers/clean { };

# `recurseIntoAttrs` for sake of hydra, not nix-env tests = recurseIntoAttrs { cc-wrapper = callPackage ../test/cc-wrapper { }; <del> cc-wrapper-clang = callPackage ../test/cc-wrapper { stdenv = clangStdenv; }; cc-wrapper-libcxx = callPackage ../test/cc-wrapper { stdenv = libcxxStdenv; }; </del> <ins> cc-wrapper-clang = callPackage ../test/cc-wrapper { stdenv = llvmPackages.stdenv; }; cc-wrapper-libcxx = callPackage ../test/cc-wrapper { stdenv = llvmPackages.libcxxStdenv; }; cc-wrapper-clang-39 = callPackage ../test/cc-wrapper { stdenv = llvmPackages_39.stdenv; }; cc-wrapper-libcxx-39 = callPackage ../test/cc-wrapper { stdenv = llvmPackages_39.libcxxStdenv; }; </ins> stdenv-inputs = callPackage ../test/stdenv-inputs { }; macOSSierraShared = callPackage ../test/macos-sierra-shared {};