cppfront
cppfront copied to clipboard
[BUG] UFCS Not Working with Pointer Dereferncing
I was experimenting a little bit and discovered that UFCS would not work on a pointer that is being de-referenced for example:
main : () -> int = {
life := 42;
p := life&;
life.someFunction();
p*.someFunction(); // Not UFCSed
}
someFunction : (x : int) -> int = {
// Do something useful...
}
Will emit the following Syntax1 code:
// ----- Cpp2 support -----
#define CPP2_USE_SOURCE_LOCATION Yes
#include "cpp2util.h"
#line 1 "helloworld.cpp2"
[[nodiscard]] auto main() -> int;
#line 9 "helloworld.cpp2"
[[nodiscard]] auto someFunction(cpp2::in<int> x) -> int;
//=== Cpp2 definitions ==========================================================
#line 1 "helloworld.cpp2"
[[nodiscard]] auto main() -> int{
auto life { 42 };
auto p { &life };
CPP2_UFCS_0(someFunction, life);
*p .someFunction(); // Fails to compile!!
}
[[nodiscard]] auto someFunction(cpp2::in<int> x) -> int{
// Do something useful...
}
Which fails to compile since we are trying to call someFunction as a member of p instead of running it through the UFCS system. I'm not entirely sure if this is intended behavior or not... but either way it is a little unintuitive.
Right, at the moment UFCS is hardcoded for just x.f(...) at a single level. When I fix the other issues about chaining it should fix this too, but it may be a couple of weeks before I get to it.
However, even now that seems odd, because without UFCS p*.f() should be generating (*p).f(), not *p.f(), just as a matter of translating the operators correctly. I'll take a look at this too -- it's almost certainly an edge case in my logic that suppresses emitting needless/redundant parens in chains of operators.
However, even now that seems odd, because without UFCS
p*.f()should be generating(*p).f(), not*p.f(), just as a matter of translating the operators correctly. I'll take a look at this too -- it's almost certainly an edge case in my logic that suppresses emitting needless/redundant parens in chains of operators.
It seems the most recent set of bug fixes fixed this particular problem (at least in my non-thoroughly unit tested experiments).