Question regarding error

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Question regarding error

John Thompson
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);
                      ^~~~
 
--
John Thompson
[hidden email]


_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: Question regarding error

Douglas Gregor

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
_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: Question regarding error

Eli Friedman
On Fri, Apr 30, 2010 at 5:11 PM, Douglas Gregor <[hidden email]> 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

_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: Question regarding error

John Thompson
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 <[hidden email]> wrote:
On Fri, Apr 30, 2010 at 5:11 PM, Douglas Gregor <[hidden email]> 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
[hidden email]


_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: Question regarding error

Eli Friedman
On Wed, May 5, 2010 at 4:40 PM, John Thompson
<[hidden email]> wrote:

> 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.

Yes, please file.

-Eli

> On Fri, Apr 30, 2010 at 5:44 PM, Eli Friedman <[hidden email]>
> wrote:
>>
>> On Fri, Apr 30, 2010 at 5:11 PM, Douglas Gregor <[hidden email]> 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
> [hidden email]
>
>
> _______________________________________________
> cfe-dev mailing list
> [hidden email]
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
>
>

_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev