Skip to content

Clang c++ compiles error with struct in template class and < operator #81731

@wangbo15

Description

@wangbo15

Please consider the following code:

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:

<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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    clang:frontendLanguage frontend issues, e.g. anything involving "Sema"confirmedVerified by a second party

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions