cppfront
cppfront copied to clipboard
[BUG] Short function syntax with multiple return values generates bad code.
Having a single expression function that uses multiple return values syntax compiles to bad cpp1 code.
fun: () -> (i:int) = i = 42;
Steps
tests % cppfront ufcs.cpp2
ufcs.cpp2... ok (all Cpp2, passes safety checks)
tests % clang++ -std=c++20 -I../cppfront/include ufcs.cpp
tests/ufcs.cpp2:24:47: error: use of undeclared identifier 'i'
[[nodiscard]] auto fun() -> fun__ret { return i.construct(42); }
^
1 error generated.
Expected result
It should fail on cppfront or compile to correct code like:
[[nodiscard]] auto fun() -> fun__ret{
cpp2::deferred_init<int> i;
i.construct(42);
return { std::move(i.value()) };
}
Actual result/error
cppfront generates bad code that fails to compile:
[[nodiscard]] auto fun() -> fun__ret { return i.construct(42); }
Compiler version
tests % clang++ --version
Apple clang version 14.0.0 (clang-1400.0.29.102)
Target: arm64-apple-darwin21.6.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin