Updating the C++ dcl.spec.auto tests

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

Updating the C++ dcl.spec.auto tests

Michael Price - Dev
I've updated the tests for paragraph 3 of the [dcl.spec.auto] section of the latest standards draft.

The patch is attached, and I'd greatly appreciate comments.  I don't think it is ready to go in, but I'm not exactly sure why.  I'm still somewhat new at this so please be gentle...

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

dcl.spec.auto.p3.patch (3K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Updating the C++ dcl.spec.auto tests

Douglas Gregor

On Dec 20, 2010, at 8:28 PM, Michael Price wrote:

> I've updated the tests for paragraph 3 of the [dcl.spec.auto] section of the latest standards draft.
>
> The patch is attached, and I'd greatly appreciate comments.  I don't think it is ready to go in, but I'm not exactly sure why.  I'm still somewhat new at this so please be gentle...

A couple comments...

-void f() {
-  auto a = a; // expected-error{{variable 'a' declared with 'auto' type cannot appear in its own initializer}}
+

Where are you deleting this? The "auto in a block" tests need to be inside a function to work properly (?)

+// The name of the variable being declared shall not appear in the initializer expression
+//
+auto initializeWithSelf = initializeWithSelf; // expected-error{{variable 'initializeWithSelf' declared with 'auto' type cannot appear in its own initializer}}

it would be good to check a more interesting initializer, too, e.g.,

  auto initializeWithSelf = 1 + &initializeWithSelf;

+// The use of auto is allowed when declaring variables in a for-init-statement
+//
+  for (auto iter = false; iter;)
+    ;
+

Also as the condition of for/if/while/switch statements, just for kicks.

+auto x = 5; // OK: x has type int
+const auto *v = &x, u = 6; // OK: v has type const int*, u has type const int

It would be good to check here that "v" actually has type "const int *", e.g., with

        const int **vp = &v;


Eventually, we'll also needs tests for 'auto' within templates.

This is a good start. Thanks for working on this!

        - 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: Updating the C++ dcl.spec.auto tests

Michael Price - Dev
See inline comments.

On Dec 20, 2010, at 11:51 PM, Douglas Gregor <[hidden email]> wrote:

>
> On Dec 20, 2010, at 8:28 PM, Michael Price wrote:
>
>> I've updated the tests for paragraph 3 of the [dcl.spec.auto]  
>> section of the latest standards draft.
>>
>> The patch is attached, and I'd greatly appreciate comments.  I  
>> don't think it is ready to go in, but I'm not exactly sure why.  
>> I'm still somewhat new at this so please be gentle...
>
> A couple comments...
>
> -void f() {
> -  auto a = a; // expected-error{{variable 'a' declared with 'auto'  
> type cannot appear in its own initializer}}
> +
>
> Where are you deleting this? The "auto in a block" tests need to be  
> inside a function to work properly (?)
>

Yeah, I wasn't too sure if a block at global scope was valid. I don't  
have any issues with turning that back into a function definition.

> +// The name of the variable being declared shall not appear in the  
> initializer expression
> +//
> +auto initializeWithSelf = initializeWithSelf; // expected-error
> {{variable 'initializeWithSelf' declared with 'auto' type cannot  
> appear in its own initializer}}
>
> it would be good to check a more interesting initializer, too, e.g.,
>
>  auto initializeWithSelf = 1 + &initializeWithSelf;
>

Agreed.

> +// The use of auto is allowed when declaring variables in a for-
> init-statement
> +//
> +  for (auto iter = false; iter;)
> +    ;
> +
>
> Also as the condition of for/if/while/switch statements, just for  
> kicks.
>

I think that one of the following paragraphs mentions condition  
statements, so I didn't include them here. I'll have to go look up the  
range-for to see where auto fits in there.

> +auto x = 5; // OK: x has type int
> +const auto *v = &x, u = 6; // OK: v has type const int*, u has type  
> const int
>
> It would be good to check here that "v" actually has type "const int  
> *", e.g., with
>
>    const int **vp = &v;
>

Might this be an opportunity to use static_assert<> and decltype, or  
do you think that would pollute the test?

>
> Eventually, we'll also needs tests for 'auto' within templates.
>

Also, perhaps lambdas should be represented in some capacity?

> This is a good start. Thanks for working on this!
>
>    - Doug
>

No, thank you for reviewing my work. I appreciate the feedback.
_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: Updating the C++ dcl.spec.auto tests

Douglas Gregor

On Dec 21, 2010, at 5:37 AM, Michael Price - Dev wrote:

> See inline comments.
>
> On Dec 20, 2010, at 11:51 PM, Douglas Gregor <[hidden email]> wrote:
>
>> +auto x = 5; // OK: x has type int
>> +const auto *v = &x, u = 6; // OK: v has type const int*, u has type const int
>>
>> It would be good to check here that "v" actually has type "const int *", e.g., with
>>
>>   const int **vp = &v;
>>
>
> Might this be an opportunity to use static_assert<> and decltype, or do you think that would pollute the test?

Unless we're testing for specific interactions, I'd rather keep the tests for these features disjoint.

>>
>> Eventually, we'll also needs tests for 'auto' within templates.
>>
>
> Also, perhaps lambdas should be represented in some capacity?

You can leave a FIXME for lambdas, if you'd like, but there's nothing we could add to the test now.

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