Open kchristin22 opened 2 months ago
I think this is kind of a duplicate of #1050, right? if so, I'm working on this
Yes, hadn't seen the issue. Thanks for noticing. Closing this.
actually, now that I think about this, it's not really a duplicate of #1050, since there I was talking about nested name qualifiers, this issue is about nested type qualifiers, if that's the right way to say it, so I'm reopening this. I apologise for the initial confusion. but I think it's a more general problem than just std::vector<>
s, it's that we need to build the type qualifiers correctly in general.
also, for anyone who's gonna be solving this, this issue is version- and machine-dependent. on my machine and with my version of Clang, the generated type for the _r0
var in the original example is std::vector::size_type
which is also incorrect because it lacks the template specification for the vector class, however it's different from the result demonstrated above.
I suspect we can get away most of the time using auto.
true, I've thought about this as well. but is it possible to generate code with auto
from the AST? I thought auto
types are removed from the code pretty early into the compilation. even stuff like auto lambda = [](){}
is printed from the visitor with a synthetic type name placeholder instead of auto
so that was my reason to believe we cannot really rely on auto.
I think utils::AddNamespaceSpecifier
could be ustilised to solve this issue if auto is not an option. but if there's a way to use auto, we probably should use it more, although I'm not sure if it's safe to always do that actually
true, I've thought about this as well. but is it possible to generate code with
auto
from the AST? I thoughtauto
types are removed from the code pretty early into the compilation. even stuff likeauto lambda = [](){}
is printed from the visitor with a synthetic type name placeholder instead ofauto
so that was my reason to believe we cannot really rely on auto.
It is possible to generate such types assuming that we know the right hand side of the assignment. In some cases auto is preferable, such as Kokkos, where the intent is to hide the implementation details and allow things to recompile for other platforms/architectures. On the other hand, using excessively auto
makes the code quite unreadable and we will need to be careful to not overuse it.
Clad generates the derivative like so:
As the comment suggests,
size_type
is not a member ofstd
, but is included insidestd::vector
. So this line should be altered to: