From: Chris Lattner Date: Sat, 7 Apr 2007 05:38:53 +0000 (+0000) Subject: Fix a bug in my earlier commit which exposed positional options backwards. X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=ee2b32082eff7366621ed2ab119deb96b7c26cec;p=oota-llvm.git Fix a bug in my earlier commit which exposed positional options backwards. This fixes llvm-ar. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@35727 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Support/CommandLine.cpp b/lib/Support/CommandLine.cpp index e349eaa514c..768bd6c05b6 100644 --- a/lib/Support/CommandLine.cpp +++ b/lib/Support/CommandLine.cpp @@ -91,6 +91,7 @@ void Option::addArgument() { static void GetOptionInfo(std::vector &PositionalOpts, std::map &OptionsMap) { std::vector OptionNames; + Option *CAOpt = 0; // The ConsumeAfter option if it exists. for (Option *O = RegisteredOptionList; O; O = O->getNextRegisteredOption()) { // If this option wants to handle multiple option names, get the full set. // This handles enum options like "-O1 -O2" etc. @@ -114,12 +115,17 @@ static void GetOptionInfo(std::vector &PositionalOpts, if (O->getFormattingFlag() == cl::Positional) PositionalOpts.push_back(O); else if (O->getNumOccurrencesFlag() == cl::ConsumeAfter) { - if (!PositionalOpts.empty() && - PositionalOpts.front()->getNumOccurrencesFlag() == cl::ConsumeAfter) + if (CAOpt) O->error("Cannot specify more than one option with cl::ConsumeAfter!"); - PositionalOpts.insert(PositionalOpts.begin(), O); + CAOpt = O; } } + + if (CAOpt) + PositionalOpts.push_back(CAOpt); + + // Make sure that they are in order of registration not backwards. + std::reverse(PositionalOpts.begin(), PositionalOpts.end()); }