···3333expandResponseParams "$@"
3434linkType=$(checkLinkType "${params[@]}")
35353636+declare -ag positionalArgs=()
3637declare -i n=0
3738nParams=${#params[@]}
3839while (( "$n" < "$nParams" )); do
···5354 *-header) dontLink=1 ;;
5455 c++*) isCxx=1 ;;
5556 esac
5757+ ;;
5858+ --) # Everything else is positional args!
5959+ # See: https://github.com/llvm/llvm-project/commit/ed1d07282cc9d8e4c25d585e03e5c8a1b6f63a74
6060+6161+ # Any positional arg (i.e. any argument after `--`) will be
6262+ # interpreted as a "non flag" arg:
6363+ if [[ -v "params[$n]" ]]; then nonFlagArgs=1; fi
6464+6565+ positionalArgs=("${params[@]:$n}")
6666+ params=("${params[@]:0:$((n - 1))}")
6767+ break;
5668 ;;
5769 -?*) ;;
5870 *) nonFlagArgs=1 ;; # Includes a solitary dash (`-`) which signifies standard input; it is not a flag
···205217if [ "$cc1" = 1 ]; then
206218 extraAfter=()
207219 extraBefore=()
220220+fi
221221+222222+# Finally, if we got any positional args, append them to `extraAfter`
223223+# now:
224224+if [[ "${#positionalArgs[@]}" -gt 0 ]]; then
225225+ extraAfter+=(-- "${positionalArgs[@]}")
208226fi
209227210228# Optionally print debug info.
+23
pkgs/test/cc-wrapper/default.nix
···1313 name = "cc-wrapper-test";
14141515 buildCommand = ''
1616+ set -o pipefail
1717+1618 NIX_DEBUG=1 $CC -v
1719 NIX_DEBUG=1 $CXX -v
1820···4143 $CC ${staticLibc} -static-pie -o cc-static-pie ${./cc-main.c}
4244 ${emulator} ./cc-static-pie
4345 ''}
4646+ ''}
4747+4848+ ${# See: https://github.com/llvm/llvm-project/commit/ed1d07282cc9d8e4c25d585e03e5c8a1b6f63a74
4949+ # `gcc` does not support this so we gate the test on `clang`
5050+ lib.optionalString stdenv.cc.isClang ''
5151+ printf "checking whether cc-wrapper accepts -- followed by positional (file) args..." >&2
5252+ mkdir -p positional
5353+5454+ # Make sure `--` is not parsed as a "non flag arg"; we should get an
5555+ # input file error here and *not* a linker error.
5656+ { ! $CC --; } |& grep -q "no input files"
5757+5858+ # And that positional file args _must_ be files (this is just testing
5959+ # that we remembered to put the `--` back in the args to the compiler):
6060+ { ! $CC -c -- -o foo ${./foo.c}; } \
6161+ |& grep -q "no such file or directory: '-o'"
6262+6363+ # Now check that we accept single and multiple positional file args:
6464+ $CC -c -DVALUE=42 -o positional/foo.o -- ${./foo.c}
6565+ $CC -o positional/main -- positional/foo.o ${./ldflags-main.c}
6666+ ${emulator} ./positional/main
4467 ''}
45684669 printf "checking whether compiler uses NIX_CFLAGS_COMPILE... " >&2