llvm-project icon indicating copy to clipboard operation
llvm-project copied to clipboard

[clang] operator< parsed as template

Open tJener opened this issue 3 years ago • 2 comments

The following fails to compile in clang unless there are parentheses around s.bazinga. gcc appears to accept this. Who is correct?

template <typename T>
struct bazinga {};

template <typename T>
struct Foo {
  struct S { int bazinga; };

  bool Bar(const S& s, int x) const {
    return s.bazinga < x;
  }
};
<source>:9:25: error: expected '>'
    return s.bazinga < x;
                        ^
<source>:9:22: note: to match this '<'
    return s.bazinga < x;
                     ^
<source>:9:25: error: expected unqualified-id
    return s.bazinga < x;
                        ^
2 errors generated.

Compiler Explorer: https://godbolt.org/z/oj86T3Taq

tJener avatar Feb 24 '23 17:02 tJener

@llvm/issue-subscribers-clang-frontend

llvmbot avatar Feb 24 '23 18:02 llvmbot

Clang is wrong here see basic.lookup.qual.general p2:

.. The lookup context of any other qualified name is the type, template, or namespace nominated by the preceding nested-name-specifier. ...

This a duplicate of: https://github.com/llvm/llvm-project/issues/59910

shafik avatar Feb 24 '23 18:02 shafik