Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clang incorrectly identifies a member variable access as a free function template name #59910

Open
dwblaikie opened this issue Jan 10, 2023 · 4 comments
Labels
clang:frontend Language frontend issues, e.g. anything involving "Sema"

Comments

@dwblaikie
Copy link
Collaborator

dwblaikie commented Jan 10, 2023

https://godbolt.org/z/radhszraP

namespace foo {

template <typename T>
struct bar {};

}

using foo::bar;

template <class T>
struct A {
  struct B {
    int bar;
  };

  bool g(B& v) {
    return v.bar < 42;
  }
};

Clang output:

<source>:17:22: error: expected '>'
    return v.bar < 42;
                     ^
<source>:17:18: note: to match this '<'
    return v.bar < 42;
                 ^
<source>:17:22: error: expected unqualified-id
    return v.bar < 42;
                     ^
2 errors generated.
@EugeneZelenko EugeneZelenko added clang:frontend Language frontend issues, e.g. anything involving "Sema" and removed new issue labels Jan 10, 2023
@llvmbot
Copy link
Collaborator

llvmbot commented Jan 10, 2023

@llvm/issue-subscribers-clang-frontend

@to268
Copy link
Contributor

to268 commented Jan 10, 2023

I'll try to investigate in the issue

@to268
Copy link
Contributor

to268 commented Jan 15, 2023

It's looks like we have a lookup bug and we treat foo::bar as an acceptable template name.
So we are using foo::bar instead of the bar field of the B struct, which is not the intended behavior.

@to268
Copy link
Contributor

to268 commented Feb 1, 2023

Aaron had a quick look at the issue and it can be also due to a parsing issue.
Because if we move struct B outside of struct A, we no longer get a compile time error,
it's the same thing when removing the template declaration from the struct.
Moreover, adding the -fdelayed-template-parsing flag fixes the issue.

CC @erichkeane

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:frontend Language frontend issues, e.g. anything involving "Sema"
Projects
None yet
Development

No branches or pull requests

4 participants