danmar / simplecpp

C++ preprocessor
BSD Zero Clause License
204 stars 80 forks source link

#pragma once usage to prevent unwanted inclusions from happening even once #363

Open datadiode opened 1 month ago

datadiode commented 1 month ago

This implements the idea behind https://github.com/danmar/simplecpp/issues/159#issuecomment-506986341 in a generic way. It works by allowing #pragma once to take a wildcard expression to sort out the unwanted include files.

Example from some project of mine, to prevent some inclusions which would otherwise cause cppcheck to abort prematurely:

#ifdef CPPCHECK
#   pragma once "boost/*"
#   pragma once "google/protobuf/*"
#   pragma once "*.pb.h"
#endif

Going with Cppcheck's --include option is particularly convenient for the purpose.

firewave commented 3 weeks ago

It is not possible to use C++11 since simplecpp still needs to support C++03.

Also using std::regex is highly discouraged because it is so slow that is essentially unusable in any production code.

datadiode commented 3 weeks ago

Would SRELL be an acceptable replacement for std::regex?

firewave commented 3 weeks ago

I guess it is sure to say that any third-party dependency is out of the question.

datadiode commented 3 weeks ago

That seems plausible. Then I'd rather go for a simplistic wildcard match, preferably by reusing the fnmatch() from https://compressionratings.com/d_archiver_template.html.