Index: llvm/lib/Support/CommandLine.cpp =================================================================== --- llvm/lib/Support/CommandLine.cpp +++ llvm/lib/Support/CommandLine.cpp @@ -1581,7 +1581,7 @@ } else { assert(ConsumeAfterOpt && NumPositionalRequired <= PositionalVals.size()); unsigned ValNo = 0; - for (size_t j = 1, e = PositionalOpts.size(); j != e; ++j) + for (size_t j = 0, e = PositionalOpts.size(); j != e; ++j) if (RequiresValue(PositionalOpts[j])) { ErrorParsing |= ProvidePositionalOption(PositionalOpts[j], PositionalVals[ValNo].first, Index: llvm/unittests/Support/CommandLineTest.cpp =================================================================== --- llvm/unittests/Support/CommandLineTest.cpp +++ llvm/unittests/Support/CommandLineTest.cpp @@ -1793,4 +1793,28 @@ clEnumValN(Val1, "bits-val1", "The Val1 value"), clEnumValN(Val1, "bits-val2", "The Val2 value"))); +TEST(CommandLineTest, ConsumeAfterTwoPositionals) { + cl::ResetCommandLineParser(); + + // input1 input2 [args] + StackOption> Input1(cl::Positional, + cl::Required); + StackOption> Input2(cl::Positional, + cl::Required); + StackOption> IntArgs(cl::ConsumeAfter); + + const char *args[] = {"prog", "input1", "input2", "arg1", "arg2"}; + + std::string Errs; + raw_string_ostream OS(Errs); + EXPECT_TRUE(cl::ParseCommandLineOptions(5, args, StringRef(), &OS)); + OS.flush(); + EXPECT_EQ("input1", Input1); + EXPECT_EQ("input2", Input2); + EXPECT_TRUE(IntArgs.size() == 2); + EXPECT_TRUE(IntArgs[0] == "arg1"); + EXPECT_TRUE(IntArgs[1] == "arg2"); + EXPECT_TRUE(Errs.empty()); +} + } // anonymous namespace