[cfe-dev] Question regarding error
Eli Friedman
eli.friedman at gmail.com
Fri Apr 30 17:44:34 PDT 2010
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
More information about the cfe-dev
mailing list