小编Per*_*Per的帖子

不明确的成员访问表达式:Clang拒绝有效代码吗?

我有一些代码,为了这个问题的目的,归结为

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);
}
Run Code Online (Sandbox Code Playgroud)

我试图用两个版本的两个编译器来编译它.GCC 4.2,4.4,4.6接受它而没有投诉.截至11月14日的Clang 2.9和SVN中继拒绝它,并显示以下错误消息:

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<EmptyClass>::static_method<TemplateClass<TemplateClass<EmptyClass>
      > >' requested here
  TemplateClass<EmptyClass>::static_method(c);
  ^
example.cc:2:7: note: lookup in the object type
      'TemplateClass<TemplateClass<EmptyClass> >' …
Run Code Online (Sandbox Code Playgroud)

c++ gcc clang language-lawyer name-lookup

23
推荐指数
2
解决办法
1855
查看次数

标签 统计

c++ ×1

clang ×1

gcc ×1

language-lawyer ×1

name-lookup ×1