[cfe-dev] Question regarding error
Douglas Gregor
dgregor at apple.com
Fri Apr 30 17:11:13 PDT 2010
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.
- Doug
More information about the cfe-dev
mailing list