bloomberg / clang-p2996

Experimental clang support for WG21 P2996 (Reflection).
https://github.com/bloomberg/clang-p2996/tree/p2996/P2996.md
51 stars 8 forks source link

Emit a diagnostic warning about parsing ambiguity in a conjunction #55

Closed BaLiKfromUA closed 6 days ago

BaLiKfromUA commented 3 months ago

Addresses #11

Testing performed

ninja: Entering directory `build-llvm/' [89/90] Running the Clang regression tests llvm-lit: /home/balik/Desktop/clang-p2996/llvm/utils/lit/lit/llvm/config.py:509: note: using clang: /home/balik/Desktop/clang-p2996/build-llvm/bin/clang

Testing Time: 0.04s

Total Discovered Tests: 19357 Excluded: 19356 (99.99%) Passed : 1 (0.01%)


- Manually tested by compiling a code with mentioned issue

```cpp
#include <experimental/meta>
#include <iostream>

enum MyEnum { x, y, e = -1, f, z = 99 };

int main() {
  MyEnum value{};
  constexpr auto reflValue = ^value; 

  if (reflValue != ^MyEnum && true) {
    std::cout << "YES" << std::endl;
  } else {
    std::cout << "NO" << std::endl;
  }
}
> build-llvm/bin/clang++ -std=c++26 -freflection -Wl,-rpath,/home/balik/Development/clang-p2996/build-llvm/lib/x86_64-unknown-linux-gnu -L/home/balik/Development/clang-p2996/build-llvm/lib/x86_64-unknown-linux-gnu -stdlib=libc++ -lc++ -lc++abi -o a.out main.cpp

main.cpp:10:28: warning: given expression may be misinterpreted due to 'T &&' type parsing logic. did you mean '... (^T) && ...'?
   10 |   if (reflValue != ^MyEnum && true) {
      |                            ^
main.cpp:10:31: error: expected ')'
   10 |   if (reflValue != ^MyEnum && true) {
      |                               ^
main.cpp:10:6: note: to match this '('
   10 |   if (reflValue != ^MyEnum && true) {
      |      ^
1 warning and 1 error generated.

Additional context

PR is ready for review IMO.

Last issue left on my side:

BaLiKfromUA commented 6 days ago

Gonna open another PR once I found proper solution