GeezerVison is showing github.com — simplecpp misparses '# #' as '##' · Issue #108 · cppcheck-opensource/simplecpp
simplecpp misparses '# #' as '##' #108DescriptionWhile analyzing issue #60, I found that
gives
test.c:1: syntax error: failed to expand 'x', Invalid ## usage when expanding 'x'.
but should give
# # Activitydanmar commented on Nov 5, 2017
but should give
hmm.. how do you know that is the expected result. The # is a preprocessor token and should be handled by the preprocessor as far as I know. What use is there in a real program? hexcoder- commented on Nov 5, 2017 Yes, '#' should be handled by the preprocessor as does '##'. But the semantics between both of them are different.
-> # and ## operators
'# #' should not be silently transformed into '##'.
The 'real use' came from issue #60 while analysing the stack trace.
For reference cpp of gcc gives this
>cat demo.cpp
#define a # #
a
>cpp -E demo.cpp
# 1 "<stdin>"
# 1 "<built-in>"
# 1 "<command-line>"
# 31 "<command-line>"
# 1 "/usr/include/stdc-predef.h" 1 3 4
# 32 "<command-line>" 2
# 1 "<stdin>"
# #
My intention was like this:
I created this new issue in order to simplify #60.
The problem in #60 might be a consequence of misparsing '# #'.
Since the misparsing happens first, I found it worthwhile to concentrate on this. amai2012 commented on Nov 7, 2017 danmar commented on Nov 11, 2017 asmwarrior commented on Jan 20, 2018 I see a very nice header only simple C Preprocessor here:glampert/parse-utils: C++ utilities for lexing and parsing of script languages and configuration files., which is a GPLv3 project, and I just comment out the line:
preprocessor.hpp | 16 ++++++++--------
1 file changed, 8 insertions(+), 8 deletions(-)
diff --git a/preprocessor.hpp b/preprocessor.hpp
index 6973cc3..3d721ba 100644
--- a/preprocessor.hpp
+++ b/preprocessor.hpp
@@ -3022,14 +3022,14 @@ bool preprocessor::expand_macro_and_append(const int macro_index, std::string *
const auto & first_tok = m_macro_tokens[macro.first_body_token];
const auto & last_tok = m_macro_tokens[macro.first_body_token + macro.body_token_count - 1];
- if (lexer::is_punctuation_token(first_tok, lexer::punctuation_id::preprocessor))
- {
- return error("\'#\' cannot appear at start of macro expansion!");
- }
- if (lexer::is_punctuation_token(last_tok, lexer::punctuation_id::preprocessor))
- {
- return error("\'#\' cannot appear at end of macro expansion!");
- }
+// if (lexer::is_punctuation_token(first_tok, lexer::punctuation_id::preprocessor))
+// {
+// return error("\'#\' cannot appear at start of macro expansion!");
+// }
+// if (lexer::is_punctuation_token(last_tok, lexer::punctuation_id::preprocessor))
+// {
+// return error("\'#\' cannot appear at end of macro expansion!");
+// }
if (lexer::is_punctuation_token(first_tok, lexer::punctuation_id::preprocessor_merge))
{
Then I see the parsed result are: # #
I use this code to run the test: parse-utils/test_eval_macros.cpp at master · glampert/parse-utils danmar commented on Jan 20, 2018 thanks for pointing out that preprocessor. For information.. a small and simple preprocessor could easily be integrated into cppcheck if it gets good enough and we see that it's actively maintained.
MetadataMetadataDevelopmentNo branches or pull requestsIssue actions
|