hsutter / cppfront

A personal experimental C++ Syntax 2 -> Syntax 1 compiler

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[BUG] Explicit discard requirement may be broken?

bluetarpmedia opened this issue · comments

Describe the bug
A recent commit may have broken the explicit discard requirement.

To Reproduce
Run cppfront on this code:

m: std::mutex = ();    // <--- Never used again

increment: (inout x) = { x++; }

main: () = {
    v1: std::vector = (11, 22, 33);
    sz:= v1.size();    // <--- Never used again

    value:= 42;
    increment(value);    // <--- inout but never used again
}

There are no errors generated.
Repro on Godbolt which at the time of writing is up-to-date with cppfront's main branch (Build 9318:2141).

Something might have updated, because it's erroring now (the error is from clang, not cppfront):

main.cpp2:10:5: error: no matching function for call to 'increment'
   10 |     increment(cpp2::move(value));
      |     ^~~~~~~~~
main.cpp2:3:6: note: candidate function [with x:auto = int] not viable: expects an lvalue for 1st argument
    3 | auto increment(auto& x) -> void{++x; }
      |      ^         ~~~~~~~

Fixing that by adding _ = value; results in:

main.cpp2:7:10: warning: unused variable 'sz' [-Wunused-variable]
    7 |     auto sz {CPP2_UFCS(size)(cpp2::move(v1))}; 
      |          ^~

Something might have updated, because it's erroring now (the error is from clang, not cppfront):

Yeah, I get subsequent warnings/errors from the compiler, but I'm pretty sure in previous versions of cppfront that cppfront itself produced an error about having to discard the variable.

I'm pretty sure in previous versions of cppfront that cppfront itself produced an error about having to discard the variable.

Could be, I don't remember one way or the other.