Skip to content

ambiguous qualified class member access lookup diagnostic unclear #11915

@zygoloid

Description

@zygoloid
mannequin
Bugzilla Link 11543
Version unspecified
OS Linux
CC @DougGregor

Extended Description

This question came up on stackoverflow:

http://stackoverflow.com/questions/8100492/ambiguous-member-access-expression-is-clang-rejecting-valid-code

Testcase, for posterity:

template<typename T>
class TemplateClass : public T {
 public:
  void method() {}
  template<typename U>
  static void static_method(U u) { u.TemplateClass::method(); }
};

class EmptyClass {};

int main() {
  TemplateClass<TemplateClass<EmptyClass> > c;
  TemplateClass<EmptyClass>::static_method(c);
}

Clearly our diagnostic for this code is insufficient, since it's taken a month and a +500 rep bounty for someone to figure out why the code is ill-formed. We say:

example.cc:6:38: error: lookup of 'TemplateClass' in member access expression is
ambiguous
static void static_method(U u) { u.TemplateClass::method(); }
^
example.cc:13:3: note: in instantiation of function template specialization
'TemplateClass::static_method<TemplateClass<TemplateClass
> >' requested here
TemplateClass::static_method(c);
^
example.cc:2:7: note: lookup in the object type
'TemplateClass<TemplateClass >' refers here
class TemplateClass : public T {
^
example.cc:2:7: note: lookup from the current scope refers here

These last two notes are clearly trying to indicate the problem, but since they don't list the template arguments they fail to point out the problem. The problem would be more obvious if we said:

example.cc:2:7: note: lookup in the object type
'TemplateClass<TemplateClass >' refers here [with T = TemplateClass]
class TemplateClass : public T {
^
example.cc:2:7: note: lookup from the current scope refers here [with T = EmptyClass]

It could also be useful to mention that the lookup found an injected-class-name (but that wouldn't help in this particular case).

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugzillaIssues migrated from bugzillac++clang:frontendLanguage frontend issues, e.g. anything involving "Sema"

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions