Skip to content
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

assert failure when combining comparison with template parameters #31

Closed
johnmcfarlane opened this issue Jul 4, 2016 · 11 comments
Closed

Comments

@johnmcfarlane
Copy link

johnmcfarlane commented Jul 4, 2016

When the following source file is passed to the standardese command

#include <type_traits>

template<int Exponent, typename std::enable_if<!(Exponent<=0) && (Exponent<8), int>::type Dummy = 0>
constexpr int pow2()
{
    return pow2<int, Exponent-1>()*2;
}

the program crashes with the following output

[info] Generating documentation for "fixed_point.h"...
standardese: /home/john/github/foonathan/standardese/src/detail/parse_utils.cpp:57: void standardese::detail::unmunch(std::__cxx11::string&): Assertion `balance == 0 || balance == -1' failed.

and balance set to 2.

It appears that the comparison operator < is being incorrectly parsed as the open brace to a template parameter list. The excerpt is part of this header file.

@foonathan foonathan added the bug label Jul 4, 2016
@foonathan
Copy link
Collaborator

Shit, yes it is.

@foonathan
Copy link
Collaborator

This fix is going to take longer, it requires restructuring part of my parsing.

@johnmcfarlane
Copy link
Author

No problem. I'm already using Doxygen and was just taking a casual 'test drive'.

Excuse my ignorance of libclang but could you ask for the template parameters as a list - rather than a flat string?

@foonathan
Copy link
Collaborator

Yes, I could and that's what my fix will be ;)

foonathan added a commit that referenced this issue Jul 7, 2016
@foonathan
Copy link
Collaborator

It was actually much more straightforward: I just need to also count the parentheses and if there are open ones, don't count the angle brackets because than we are inside an expression.

It is now fixed on the develop branch.

@johnmcfarlane
Copy link
Author

This is still happening but on a different line:

str="typename std::enable_if<\nExponent<0,\nint>::type"
balance=1
parens = 0

The project I linked to above is full of equally gnarly templates.

@foonathan
Copy link
Collaborator

I see that I can parse the entire project then before coming back :D

@johnmcfarlane
Copy link
Author

That would be nice. 😄 If you can get fixed_point.h working, you'll be half-way there.

foonathan added a commit that referenced this issue Jul 9, 2016
@foonathan
Copy link
Collaborator

Now it is fixed.

This issue can only occur for specializations again because otherwise I simply removed the code that looks at the template parameters and did an alternative.

Note that standardese cannot parse your auxiliary headers, to be precise: the functions generated by macros due to a bug with libclang. But the public headers work and only they need to be documented, right?

@johnmcfarlane
Copy link
Author

Thanks. That sounds like a problem that should mostly affect integer.h. For comparison here's fixed_point.h in both Standardese and Doxygen. Not bad for a source file marked up for Doxygen. Clearly, some work would be required get the best results.

@foonathan
Copy link
Collaborator

There seems to be a regression with the formatting of namespaces (closing bracket in the same line as the last entity).

And I also need to tweak some things in the output.

But my overall goal with standardese is that you can get the same format as the C++ standard documentation with the right markup. This could be useful for you proposal writers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants