[cfe-dev] Updating the C++ dcl.spec.auto tests

Michael Price - Dev michael.b.price.dev at gmail.com
Tue Dec 21 05:37:20 PST 2010


See inline comments.

On Dec 20, 2010, at 11:51 PM, Douglas Gregor <dgregor at apple.com> 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.



More information about the cfe-dev mailing list