hsutter / cppfront

A personal experimental C++ Syntax 2 -> Syntax 1 compiler
Other
5.43k stars 237 forks source link

[BUG] `is * const _` unconditionally `true` #427

Open JohelEGP opened 1 year ago

JohelEGP commented 1 year ago

Title: is * const _ unconditionally true.

Minimal reproducer (https://cpp2.godbolt.org/z/1TT333zb6):

main: () = {
  x := 0;
  x is const * const _;
  x is * const _;
  x is const * _;
  x is const _;
  x is * _;
  x is _;
}

Commands:

cppfront -clean-cpp1 main.cpp2
clang++17 -std=c++2b -stdlib=libc++ -lc++abi -pedantic-errors -Wall -Wextra -Wconversion -I . main.cpp

Expected result:

According to the proposal, I guess. I'd expect the test cases to check whether the expression's type has those qualifiers. x is const _ would be a nice way of asking "is x const?"

Actual result and error:

  true;
  true;
  true;
  true;
  true;
  true;
Cpp2 lowered to Cpp1. ```C++ #include "cpp2util.h" auto main() -> int; auto main() -> int{ auto x {0}; true; true; true; true; true; true; } ```
Warnings. ```output build/_cppfront/main.cpp:9:8: warning: unused variable 'x' [-Wunused-variable] auto x {0}; ^ build/_cppfront/main.cpp:10:3: warning: expression result unused [-Wunused-value] true; ^~~~ build/_cppfront/main.cpp:11:3: warning: expression result unused [-Wunused-value] true; ^~~~ build/_cppfront/main.cpp:12:3: warning: expression result unused [-Wunused-value] true; ^~~~ build/_cppfront/main.cpp:13:3: warning: expression result unused [-Wunused-value] true; ^~~~ build/_cppfront/main.cpp:14:3: warning: expression result unused [-Wunused-value] true; ^~~~ build/_cppfront/main.cpp:15:3: warning: expression result unused [-Wunused-value] true; ^~~~ 7 warnings generated. Program returned: 0 ```

Other observations:

I think it's reasonable for even x is _ to not be unconditionally true for template metaprogramming purposes where non-dependent true would be a hard error.

JohelEGP commented 1 year ago

See P2392 § 2.3.1, 3.2.2.