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

Infinite recursion while detecting SFINAE #665

Closed
Nerixyz opened this issue Sep 2, 2024 · 1 comment · Fixed by #682
Closed

Infinite recursion while detecting SFINAE #665

Nerixyz opened this issue Sep 2, 2024 · 1 comment · Fixed by #682
Assignees

Comments

@Nerixyz
Copy link
Contributor

Nerixyz commented Sep 2, 2024

I was trying to compile MrDocs and ran into a stack-overflow while building the documentation for MrDocs itself (which is build by default).

The error occurs when trying to detect whether fmt::formatter is such a template. One of its specializations is in mrdocs/Dom/String.hpp. In this specialization, the fmt::formatter extends its own template. When checking for SFINAE, the base template is checked as well, leading to infinite recursion.

The following change "fixes" the issue, but I don't know if it's correct to just "ignore" that base class.

diff --git a/src/lib/AST/ASTVisitor.cpp b/src/lib/AST/ASTVisitor.cpp
index 1d48999..893997e 100644
--- a/src/lib/AST/ASTVisitor.cpp
+++ b/src/lib/AST/ASTVisitor.cpp
@@ -1723,6 +1723,8 @@ public:
                             return true;
                         continue;
                     }
+                    if (sfinae_info->Template == TD)
+                        continue;
                     auto sfinae_result = isSFINAETemplate(
                         sfinae_info->Template, Member);
                     if(! sfinae_result)

Minimal example:

template <typename T> struct Foo {};
template<> struct Foo<char> : public Foo<int> {};

This isn't caught in CI, as the docs generation is disabled there.


Aside:

@alandefreitas
Copy link
Collaborator

alandefreitas commented Oct 1, 2024

I just reproduced the problem and can confirm it. For reference, I built the MrDocs documentation with:

mrdocs \
	--config="path\to\mrdocs\docs\mrdocs.yml" \
	--output="path\to\mrdocs\build\reference" \
	--addons=path/to/mrdocs/share/mrdocs/addons \
	--stdlib-includes=path/to/libraries/llvm/include \
	--concurrency 1 \
	--compilation-database=path\to\mrdocs\build\release-msvc\compile_commands.json

(omitting the path/to/mrdocs for brevity and privacy)

The stack trace is something like:

@sdkrystian Please have a look at this logic and the proposed solution:

+                    if (sfinae_info->Template == TD)
+                        continue;

My intuition is the solution is going to be more complex than that.

The documentation generation from CMake doesn't work right now, because it tries to find a local-antora-playbook.yml - this should probably be antora-playbook.yml.

I opened another issue for this one: #680

MSVC fails to compile lib/AST/ASTVisitor.cpp, because CompleteExternalDeclaration is overridden with a DeclaratorDecl*, but declared with a VarDecl* in the version referenced on https://mrdocs.com/docs/mrdocs/install.html (7a28a5b3fee6c78ad59af79a3d03c00db153c49f; I suppose that version is outdated)

Interesting. But yes, this should be done in develop because we have no problems in CI.

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

Successfully merging a pull request may close this issue.

3 participants