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

[domain:cpp] decltype or possible nested template issue, bug report auto-requested by sphinx #4094

Closed
svenevs opened this issue Sep 28, 2017 · 4 comments

Comments

@svenevs
Copy link
Contributor

svenevs commented Sep 28, 2017

Subject: bug report of nested template or possible decltype hiccup. I lean toward decltype being the problem because the false_type is happy. Or maybe it's the & (there could also be a * btw).

Problem

  • Sphinx asked me to report the bug
/* primary template handles types that have no nested ::var variable */
template <class, class = std::void_t<>>
struct has_var : std::false_type { };

/* specialization recognizes types that do have a nested ::var variable */
template <class T>
struct has_var<T, std::void_t<decltype(&T::var)>> : std::true_type { };
//                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Procedure to reproduce the problem

In a vanilla index.rst:

.. cpp:class:: template <class, class = std::void_t<>> has_var

   Trap state, inherits from ``std::false_type``.

.. cpp:class:: template <class T> has_var<T, std::void_t<decltype(&T::var)>>

   Specialization for when ``T::var`` exists, inherits from ``std::true_type``.

Error logs / results

Sphinx 1.6.4:

WARNING: Index id generation for C++ object "template<class T> has_var<T, std::void_t<decltype(&T::var)>>" failed, please report as bug (id=_CPPv2I0E7has_varI1TNSt6void_tIXdecltype(&T::var)EEEE).

For what it's worth, Sphinx 1.6.3's behavior here may actually be better (?). I whittled this down for using pure sphinx directives. I actually came here from a Breathe directive

.. doxygenstruct:: has_video_height< T, std::void_t< decltype(&T::video_height)> >
   :members:
   :protected-members:
   :undoc-members:

1.6.3 will warn but accept, 1.6.4 errors out on assert False in checkType.

The 1.6.3 implementation is different. The diff

--- 163	2017-09-28 11:03:09.000000000 -0700
+++ 164	2017-09-28 11:03:13.000000000 -0700
@@ -3,14 +3,8 @@
         return True
     if declTyp == 'templateParam':
         return True
-    if typ == 'var' or typ == 'member':
-        return declTyp in ['var', 'member']
-    if typ in ['enum', 'enumerator', 'function', 'class', 'concept']:
-        return declTyp == typ
-    validForType = ['enum', 'class', 'function', 'type']
-    if typ == 'typeOrConcept':
-        return declTyp == 'concept' or declTyp in validForType
-    if typ == 'type':
-        return declTyp in validForType
-    print("Type is %s" % typ)
+    objtypes = self.objtypes_for_role(typ)
+    if objtypes and declTyp in objtypes:
+        return True
+    print("Type is %s, declType is %s" % (typ, declTyp))
     assert False

But I'm honestly pretty lost on how one assert False (in 1.6.4), but the other doesn't...

Please let me know if you'd like me to make a full-fledged example repo (e.g. the problem isn't obvious to you the sphinx-gods) and I will. Breathe requires extra setup (running doxygen, etc).

Expected results

No link error?

Reproducible project / your project

Just paste the rst above in any sphinx project.

Environment info

  • OS: Linux or mac
  • Python version: 3.6.2
  • Sphinx version: 1.6.4
@jakobandersen
Copy link
Contributor

Thanks for reporting, there are quite a few things:

  • Sphinx 1.6.4 has very simple "parsing" of expressions, which for example means that identifiers are not converted to links in them, and that no proper ids are generated (which is the warning you see).
  • The master branch, which will become Sphinx 1.7, has much better expression parsing support (and a expr role for inline text to be parsed and hyperlinked).
  • The master branch had a bug with empty template argument lists (e.g., in std::void_t<>) which should be fixed now.
  • However, general decltype(<expr>) parsing is not enabled on master yet, so a hard error instead of a warning will be triggered (though that error message has problems as well). I will see if I can get it enabled soon.
  • I'm not sure how the checkType problem arose, or how to reproduce it. Can you open a separate bug report for that? Is the project where it occurs publicly available?

@svenevs
Copy link
Contributor Author

svenevs commented Sep 29, 2017

The master branch had a bug with empty template argument lists (e.g., in std::void_t<>) which should be fixed now.

Righto!

However, general decltype() parsing is not enabled on master yet, so a hard error instead of a warning will be triggered (though that error message has problems as well). I will see if I can get it enabled soon.

Hmm. Well, to be honest I am really confused now and think this statement may not be accurate.

.. cpp:class:: template <class T> has_var<T, internal::void_t<decltype(&T::var)>>

   specialization recognizes types that do have a nested ``var`` variable

Works...

I'm not sure how the checkType problem arose, or how to reproduce it. Can you open a separate bug report for that? Is the project where it occurs publicly available?

Flabbergasted is probably the right answer here. I can't reproduce this anymore either. I made a testing repository, but am now no longer able to even get Breathe to find the has_var that uses decltype(&T::var).

I started in on all of this from breathe/#354, wanting to fix template specializations and using statements. I'm gonna have to put this down for a bit, if I'm actually able to reproduce this I'll open the new issue...but until I can get Breathe to actually find things, I can't get the assert False to fail out 😢

@mitya57
Copy link
Contributor

mitya57 commented Sep 30, 2017

But I'm honestly pretty lost on how one assert False (in 1.6.4), but the other doesn't...

This is fixed in my pull request #4096.

@jakobandersen
Copy link
Contributor

Parsing of decltype(<expr>) should now work in the master branch.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 22, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants