-
Notifications
You must be signed in to change notification settings - Fork 82
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
#pragma once usage to prevent unwanted inclusions from happening even once #363
Conversation
fb3f18d
to
414909d
Compare
It is not possible to use C++11 since simplecpp still needs to support C++03. Also using |
Would SRELL be an acceptable replacement for |
I guess it is sure to say that any third-party dependency is out of the question. |
That seems plausible. |
… happening even once
…comparison rather than an assignment operator
f0c55c7
to
f7fbdd1
Compare
f7fbdd1
to
90a17cc
Compare
@datadiode @firewave FYI: this library is the state of the art solution for compile-time-baking of regexp engine in c++ (source: cppcon first presentation of Herb): |
Thanks for the suggestion. I think CTRE is awesome!! but it requires modern compilers. and minimum c++17 as far as I know. |
@@ -3292,6 +3292,40 @@ static std::string getTimeDefine(const struct tm *timep) | |||
return std::string("\"").append(buf).append("\""); | |||
} | |||
|
|||
// Reuse some code from https://compressionratings.com/d_archiver_template.html | |||
// SPDX-License-Identifier: CC0-1.0 | |||
class simplecpp::Mask : public std::string { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel this Mask class is not very elegant imho.
- I don't feel it should inherit from std::string, it's not used as a std::string.
- I dont see the point to read the i flag from the string in the constructor like that instead of passing a parameter. Will there be unintentional case matching if the string contains a random "i" somewhere or not.
- the fnmatch shouldn't be a template function
- I don't see why match a
const char*
instead of a std::string.. seems redundant to call .c_str()
// # pragma once "google/protobuf/*" | ||
// # pragma once "*.pb.h" | ||
// #endif | ||
std::set<Mask> pragmaOddOnce; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
well it could be std::set<std::string> pragmaOnceMasks;
.. instead of creating a Mask class what would be the downside to just provide a regular function like:
bool match(const std::string& mask, const std::string& value, bool i);
I don't see that #159 talks about I reopened the #159 I think I was too quick to close it before. I have never seen this |
The invented extension to the
|
That hardcoding does feel worse. However this simplecpp hack is not the ideal solution. When I read #159 it does seem that we have many problems but missing defines is a major one. That is not a simplecpp bug. It should be the responsibility of the tool (i.e. cppcheck) to provide proper defines. We have some cppcheck ticket(s) about teaching cppcheck defines better. If cppcheck command |
I did think of proposing them a command line option to tell cppcheck to ignore any include paths it picks up from a project file if they match some regular expression. Will go ahead with that idea. |
That already exists. It is the |
According to the usage information, |
You are of course right. I might have been thinking of something else (and maybe something I needed at some point). It might also play into https://trac.cppcheck.net/ticket/12359 and https://trac.cppcheck.net/ticket/13204. |
This implements the idea behind #159 (comment) 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:
Going with Cppcheck's --include option is particularly convenient for the purpose.