Issue 81731
Summary Clang c++ compiles error with struct in template class and < operator
Labels clang
Assignees
Reporter wangbo15
    Please consider the following code:

```c++
template<class T>
class confused{};

template<class T>
class test
{
    void foo() {
        if(this->b.confused < 1);
    };

    struct bar
 {
        int confused;
    } b;
};
```
Clang rejects it by giving such considerably puzzling output:

```c++
<source>:8:32: error: expected '>'
    8 |         if(this->b.confused < 1);
      | ^
<source>:8:29: note: to match this '<'
 8 |         if(this->b.confused < 1);
      | ^
<source>:8:32: error: expected unqualified-id
    8 | if(this->b.confused < 1);
      | ^
<source>:8:33: warning: if statement has empty body [-Wempty-body]
 8 |         if(this->b.confused < 1);
      | ^
<source>:8:33: note: put the semicolon on a separate line to silence this warning
1 warning and 2 errors generated.
Compiler returned: 1
```

We suppose that's because the compiler has found incorrect local variable name of `confused` by confusing the global template class declared above with the integer member variable declared in the nested class `bar` inside `test`

Please check [https://godbolt.org/z/7afqsvEvo](https://godbolt.org/z/7afqsvEvo).
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to