<div dir="ltr">On Thu, Apr 18, 2013 at 10:09 AM, Nico Weber <span dir="ltr"><<a href="mailto:thakis@chromium.org" target="_blank">thakis@chromium.org</a>></span> wrote:<br><div class="gmail_extra"><div class="gmail_quote">
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Hi Richard,<div><br></div><div>this breaks compilation of this bit of code in WebKit, which does metaprogramming to check if a class implements a given method:</div>
<div><br></div><div><div>template <typename Type> class IsInstrumented {</div>
<div>  class yes { char m; };</div><div>  class no { yes m[2]; };</div><div>  struct BaseMixin {</div><div>    void reportMemoryUsage() const {}</div><div>  };</div><div>  struct Base : public Type, public BaseMixin {</div>

<div>  };</div><div>  template <typename T, T t> class Helper {</div><div>  };</div><div>  template <typename U></div><div>  static no</div><div>  deduce(U *, Helper<void(BaseMixin::*)() const, &U::reportMemoryUsage> * = 0);</div>

<div>  static yes deduce(...);</div><div>public:</div><div>  static const bool result = sizeof(yes) == sizeof(deduce((Base *)(0)));</div><div>};</div><div><br></div><div>template <typename T> bool hasReportMemoryUsage(const T *object) {</div>

<div>  return IsInstrumented<T>::result;</div><div>}</div><div><br></div><div>class Timer {</div><div>  void operator delete(void *p) {}</div><div>public:</div><div>  virtual ~Timer();</div><div>};</div><div>bool f() {</div>

<div>  Timer m_cacheTimer;</div><div>  return hasReportMemoryUsage(&m_cacheTimer);</div><div>}</div></div><div><br></div><div><br></div><div>The error message looks like this:</div><div><br></div><div>
<div>$ clang -c repro.ii -std=gnu++11  # works in older clang</div><div>$ third_party/llvm-build/Release+Asserts/bin/clang -c repro.ii -std=gnu++11</div><div>repro.ii:7:10: error: deleted function '~Base' cannot override a non-deleted function</div>

<div>  struct Base : public Type, public BaseMixin {</div><div>         ^</div><div>repro.ii:13:51: note: in instantiation of member class 'IsInstrumented<Timer>::Base' requested here</div><div>  deduce(U *, Helper<void(BaseMixin::*)() const, &U::reportMemoryUsage> * = 0);</div>

<div>                                                  ^</div><div>repro.ii:13:3: note: while substituting deduced template arguments into function template 'deduce' [with U = IsInstrumented<Timer>::Base]</div>

<div>  deduce(U *, Helper<void(BaseMixin::*)() const, &U::reportMemoryUsage> * = 0);</div><div>  ^</div><div>repro.ii:20:10: note: in instantiation of template class 'IsInstrumented<Timer>' requested here</div>

<div>  return IsInstrumented<T>::result;</div><div>         ^</div><div>repro.ii:30:10: note: in instantiation of function template specialization 'hasReportMemoryUsage<Timer>' requested here</div><div>

  return hasReportMemoryUsage(&m_cacheTimer);</div><div>         ^</div><div>repro.ii:26:11: note: overridden virtual function is here</div><div>  virtual ~Timer();</div><div>          ^</div><div>1 error generated.</div>

<div><br></div></div><div><br></div><div>Is this expected? I suppose so, but the diagnostic is a bit hard to read (it's not clear to me why ~Base() is deleted).</div></div></blockquote><div><br></div><div style>Yes, the diagnostic seems to be correct, if unhelpful. Feel free to file a bug on the diagnostic (if not, I'll try to remember to fix this but can't promise!). We should be pointing out that the function is implicitly deleted because it would otherwise try to call an inaccessible class-specific 'operator delete'.</div>
<div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div>It compiles fine if I give Base an explicit destructor. Is this the right fix?</div></div>
</blockquote><div><br></div><div style>It's inelegant, but yes, that should work (unless you use this with a final class or similar...). The check itself looks a bit odd -- usually, one would check whether a certain expression is valid (something like putting sizeof(declval<Type>().reportMemoryUsage()) into your SFINAE context) rather than checking whether a member with the given name exists -- but assuming it's getting the effect you want, I'll have a think about a more reliable way to perform the test.</div>
</div></div></div>