@@ -186,30 +186,40 @@ bool CppCheckExecutor::parseFromArgs(Settings &settings, int argc, const char* c
186186 logger.printMessage (" Please use --suppress for ignoring results from the header files." );
187187 }
188188
189- const std::vector<std::string>& pathnames = parser.getPathNames ();
190- const std::list<FileSettings>& fileSettings = parser.getFileSettings ();
189+ const std::vector<std::string>& pathnamesRef = parser.getPathNames ();
190+ const std::list<FileSettings>& fileSettingsRef = parser.getFileSettings ();
191191
192192 // the inputs can only be used exclusively - CmdLineParser should already handle this
193- assert (!(!pathnames .empty () && !fileSettings .empty ()));
193+ assert (!(!pathnamesRef .empty () && !fileSettingsRef .empty ()));
194194
195- if (!fileSettings.empty ()) {
195+ if (!fileSettingsRef.empty ()) {
196+ std::list<FileSettings> fileSettings;
196197 if (!settings.fileFilters .empty ()) {
197198 // filter only for the selected filenames from all project files
198- std::copy_if (fileSettings .cbegin (), fileSettings .cend (), std::back_inserter (mFileSettings ), [&](const FileSettings &fs) {
199+ std::copy_if (fileSettingsRef .cbegin (), fileSettingsRef .cend (), std::back_inserter (fileSettings ), [&](const FileSettings &fs) {
199200 return matchglobs (settings.fileFilters , fs.filename );
200201 });
201- if (mFileSettings .empty ()) {
202+ if (fileSettings .empty ()) {
202203 logger.printError (" could not find any files matching the filter." );
203204 return false ;
204205 }
205206 }
206207 else {
207- mFileSettings = fileSettings ;
208+ fileSettings = fileSettingsRef ;
208209 }
210+
211+ // sort the markup last
212+ std::copy_if (fileSettings.cbegin (), fileSettings.cend (), std::back_inserter (mFileSettings ), [&](const FileSettings &fs) {
213+ return !settings.library .markupFile (fs.filename ) || !settings.library .processMarkupAfterCode (fs.filename );
214+ });
215+
216+ std::copy_if (fileSettings.cbegin (), fileSettings.cend (), std::back_inserter (mFileSettings ), [&](const FileSettings &fs) {
217+ return settings.library .markupFile (fs.filename ) && settings.library .processMarkupAfterCode (fs.filename );
218+ });
209219 }
210220
211- if (!pathnames .empty ()) {
212- std::list<std::pair<std::string, std::size_t >> files ;
221+ if (!pathnamesRef .empty ()) {
222+ std::list<std::pair<std::string, std::size_t >> filesResolved ;
213223 // TODO: this needs to be inlined into PathMatch as it depends on the underlying filesystem
214224#if defined(_WIN32)
215225 // For Windows we want case-insensitive path matching
@@ -219,26 +229,36 @@ bool CppCheckExecutor::parseFromArgs(Settings &settings, int argc, const char* c
219229#endif
220230 // Execute recursiveAddFiles() to each given file parameter
221231 const PathMatch matcher (ignored, caseSensitive);
222- for (const std::string &pathname : pathnames ) {
223- const std::string err = FileLister::recursiveAddFiles (files , Path::toNativeSeparators (pathname), settings.library .markupExtensions (), matcher);
232+ for (const std::string &pathname : pathnamesRef ) {
233+ const std::string err = FileLister::recursiveAddFiles (filesResolved , Path::toNativeSeparators (pathname), settings.library .markupExtensions (), matcher);
224234 if (!err.empty ()) {
225235 // TODO: bail out?
226236 logger.printMessage (err);
227237 }
228238 }
229239
240+ std::list<std::pair<std::string, std::size_t >> files;
230241 if (!settings.fileFilters .empty ()) {
231- std::copy_if (files .cbegin (), files .cend (), std::inserter (mFiles , mFiles .end ()), [&](const decltype (files )::value_type& entry) {
242+ std::copy_if (filesResolved .cbegin (), filesResolved .cend (), std::inserter (files, files .end ()), [&](const decltype (filesResolved )::value_type& entry) {
232243 return matchglobs (settings.fileFilters , entry.first );
233244 });
234- if (mFiles .empty ()) {
245+ if (files .empty ()) {
235246 logger.printError (" could not find any files matching the filter." );
236247 return false ;
237248 }
238249 }
239250 else {
240- mFiles = files ;
251+ files = std::move (filesResolved) ;
241252 }
253+
254+ // sort the markup last
255+ std::copy_if (files.cbegin (), files.cend (), std::inserter (mFiles , mFiles .end ()), [&](const decltype (files)::value_type& entry) {
256+ return !settings.library .markupFile (entry.first ) || !settings.library .processMarkupAfterCode (entry.first );
257+ });
258+
259+ std::copy_if (files.cbegin (), files.cend (), std::inserter (mFiles , mFiles .end ()), [&](const decltype (files)::value_type& entry) {
260+ return settings.library .markupFile (entry.first ) && settings.library .processMarkupAfterCode (entry.first );
261+ });
242262 }
243263
244264 if (mFiles .empty () && mFileSettings .empty ()) {
0 commit comments