Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why must 'auto' declarations all be of the same type?

It appears that it is not allowed to declare multiple variables of distinct types using the auto keyword. I can't figure out the wording in the standard that would prevent it however.

auto i = 1, j = 1.0; //deduction failure (several compilers)

Historically I understand since you have only one decl-specifier-spec. However, the rules in the standard don't seem to preclude, in fact they encourage, that auto can be a distinct type for each. Consider these paragraphs:

8-3 Each init-declarator in a declaration is analyzed separately as if it was in a declaration by itself.

7.1.6.4-7 If the list of declarators contains more than one declarator, the type of each declared variable is determined as described above. [...]

Even without auto not all variables needed to have the same type, as certain modifiers like * could be applied to each declarator individually. To me it appears now that the wording allows each auto declarator to be a completely distinct type.

Which paragraph would prohibit this?

like image 541
edA-qa mort-ora-y Avatar asked May 20 '13 03:05

edA-qa mort-ora-y


People also ask

What is an auto declaration?

An Auto Insurance Policy Declarations summarizes your policy and the coverages, limits and deductibles you've chosen to purchase. It can also list the insured vehicles, insured drivers and dates your policy is effective as well as any discounts you received.

Why is the declaration page important?

A declarations page is important because it summarizes the key points about your policy. It details what you're insuring, how your coverage works, and how much it costs.

What is an auto insurance declarations page?

Your declarations page lists the names of all insured drivers. This includes the policyholder and any additional drivers covered under the same policy. Vehicles covered: All cars covered by your auto insurance policy are listed on your declarations page. These are identified by make, model, year, and VIN.

What's in the declaration in insurance?

It includes your name and address, descriptions of the insured property and your premium. It also outlines your policy's coverages, limits, deductibles, discounts and relevant insurance policy forms and endorsements.


1 Answers

Type deduction is performed for every object in the list, but the final result must be a single type [dcl.spec.auto]/7 (emphasis mine):

If the list of declarators contains more than one declarator, the type of each declared variable is determined as described above. If the type deduced for the template parameter U is not the same in each deduction, the program is ill-formed.

like image 73
Mankarse Avatar answered Oct 05 '22 10:10

Mankarse