[PATCH] N3323 -- Tweak to certain C++ contextual conversions

Richard Smith richard at metafoo.co.uk
Thu May 30 17:54:07 PDT 2013


On Thu, May 30, 2013 at 4:35 PM, Larisse Voufo <lvoufo at google.com> wrote:

> Please see attached.
>

This looks really good.

Something funny has happened around < >s for templates. I've run the patch
through clang-format for you (attached).


+                // Fixme: this assumes that both types will be equally
+                // restrict-qualified.

s/Fixme/FIXME/


+                if (ToType.isMoreQualifiedThan(CurToType))
+                  ToType = CurToType;

The standard doesn't seem very clear on this, but I think you should merge
qualifiers here rather than taking the more-qualified type. If we have a
conversion to 'const T' and a conversion to 'volatile T', our current
choice between them seems to depend on the order in which we see them.


+      if (ConvTemplate)
+        AddTemplateConversionCandidate(ConvTemplate, FoundDecl,
ActingContext,
+                                       From, ToType, CandidateSet);

It looks like ViableConversions won't contain any conversion operator
templates at this point. However, we should probably be performing overload
resolution on the complete set of conversions, not just on the ones we
matched earlier, for oddball cases like:

  struct A {
    operator int() &&;
    template<typename T> operator T();
  };
  void f(A a) {
    switch (a) {} // should presumably call templated conversion operator
to convert to int.
  }
  struct B {
    operator bool() &&;
    operator void*();
  };
  void g(B b) {
    switch (b) {} // should presumably call 'b.operator void*()' then
convert result to bool
  }

The patch could do with more testcases, covering more exotic situations
such as the above, and the new error cases.

Thanks!
Richard
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20130530/11ab2396/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: n3323-contextual-conversion-clang-format.diff
Type: application/octet-stream
Size: 16220 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20130530/11ab2396/attachment.obj>


More information about the cfe-commits mailing list