[cfe-dev] Question regarding error
John Thompson
john.thompson.jtsoftware at gmail.com
Wed May 5 16:40:56 PDT 2010
Note that in the actual code, the vector constructor is explicit:
class test
{
public:
test( float x );
explicit test(__attribute__((vector_size(16))) float v );
};
Shouldn't that help the compiler decide that it's not a candidate? (gcc
doesn't seem to care either way.)
I have one class like this that is used frequently. I added a constructor
taking an int, but that caused other problems. Adding a (float) cast to the
argument in the instanciations is the hack that seems to work.
Also, because you can't cast scalars to vectors, I think the implicit
conversion code should exclude the vector case. If you agree, I'll file a
bug.
On Fri, Apr 30, 2010 at 5:44 PM, Eli Friedman <eli.friedman at gmail.com>wrote:
> On Fri, Apr 30, 2010 at 5:11 PM, Douglas Gregor <dgregor at apple.com>
> wrote:
> >
> > On Apr 30, 2010, at 4:55 PM, John Thompson wrote:
> >
> >> This doesn't compile. Should it?:
> >>
> >> class test
> >> {
> >> public:
> >> test( float x );
> >> test(__attribute__((vector_size(16))) float v );
> >> };
> >> int vi = 0;
> >> void func()
> >> {
> >> test object = test(vi);
> >> }
> >> C:\Sony\Clang\exp>clang -cc1 scalar.cpp
> >> scalar.cpp:13:16: error: functional-style cast from 'int' to 'test' is
> not allowed
> >> test object = test(vi);
> >> ^~~~
> >
> > The logic for computing implicit conversion sequences in C++ does not
> know anything about vectors. What you're seeing here is a poor diagnostic
> due to the cast. Change it to a direct initialization and you'll see the
> ambiguity:
> >
> > t2.cpp:10:7: error: call to constructor of 'test' is ambiguous
> > test object(vi);
> > ^ ~~
> > t2.cpp:4:2: note: candidate constructor
> > test( float x );
> > ^
> > t2.cpp:5:2: note: candidate constructor
> > test(__attribute__((vector_size(16))) float v );
> > ^
> > t2.cpp:1:7: note: candidate is the implicit copy constructor
> > class test
> > ^
> >
> > Clang can't figure out which constructor is the better match.
>
> Right, it's treating it like a class which has constructors for, for
> example, float and double. It does this because our routines for
> identifying types do strange things for queries like
> isRealFloatingType(). See also
> http://llvm.org/bugs/show_bug.cgi?id=4208 .
>
> -Eli
>
--
John Thompson
John.Thompson.JTSoftware at gmail.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20100505/a36d2956/attachment.html>
More information about the cfe-dev
mailing list