slycelote / caide-cpp-inliner

Transform a C++ program consisting of multiple source files and headers into a single self-contained source file without any external dependencies (except for standard system headers). Unused code is not included in the resulting file.
Other
32 stars 12 forks source link

Type alias is removed #3

Closed AlCash07 closed 7 years ago

AlCash07 commented 7 years ago

using iterator_category = std::input_iterator_tag; Type aliases like this one inside my iterator classes are removed even with the // caide keep comment.

slycelote commented 7 years ago

Can you provide an example where even /// caide keep doesn't help?

AlCash07 commented 7 years ago

Looks like I was trying to write the comment on the same line, while it should go before. Anyway, here's an example where type alias is removed, which changes the output from 1 to 0: http://ideone.com/74nIGF

slycelote commented 7 years ago

This is fixed now. However, there is a caveat specifically for iterator_category and similar cases.

For instance, a custom iterator passed to std::shuffle must satisfy RandomAccessIterator concept, which means that it must provide a certain number of member functions/type aliases. However, there is no way to detect this requirement, unless both the language and the standard library have full concept support (which we don't want to rely on). That's because some of the functions/type aliases required by the concept might not actually be used by a particular STL implementation. If we remove them, the program becomes technically illegal and may not even compile in another compiler.

To work around that, it's possible to mark declarations required by some Concept with a comment /// caide concept. This will ensure these declarations don't get removed as long as the class containing them is used.