ned14 / pcpp

A C99 preprocessor written in pure Python
Other
220 stars 41 forks source link

Macros in #include are not supported #47

Closed schra closed 4 years ago

schra commented 4 years ago

Observation

$ wget https://raw.githubusercontent.com/chriskohlhoff/asio/be7badc31abcc395cf868de6a1e240c2350bdbf2/asio/include/asio/detail/handler_tracking.hpp
$ pcpp handler_tracking.hpp --passthru-unfound-includes --passthru-unknown-exprs > /dev/null
handler_tracking.hpp:27 error: Malformed #include statement

where line 27 is:

# include ASIO_CUSTOM_HANDLER_TRACKING

C99 standard reference

In 6.10.2 of the C99 standard you can read:

A preprocessing directive of the form

include pp-tokens new-line

(that does not match one of the two previous forms) is permitted.The preprocessing tokens after include in the directive are processed just as in normal text. (Each identifier currently defined as a macro name is replaced by its replacement list of preprocessing tokens.) The directive resulting after all replacements shall match one of the two previous forms

Furthermore, the current C++ draft still has this behavior: http://eel.is/c++draft/cpp.include#4

ned14 commented 4 years ago

The cause was in fact that passthrough mode for including macros wasn't supported. Without passthrough mode including macros works as expected. It is now fixed, thanks for reporting this issue.