cplusplus / CWG

Core Working Group
24 stars 7 forks source link

CWG2776 [temp.inst] Infinite recursion in instantiation shouldn't be undefined behavior #343

Open frederick-vs-ja opened 1 year ago

frederick-vs-ja commented 1 year ago

Full name of submitter (unless configured in github; will be published with the issue): Jiang An

Reference (section label): [temp.inst]

Link to reflector thread (if any):

Issue description:

Whether there is infinite recursion in instantiation is a static property of a program, so infinite recursion in instantiation should make the program ill-formed.

Additionally, [expr.const] p5.8 requires detection for core UB in constant evaluation, which seems impossible for infinite recursion in instantiation, because we must start constant evaluation after instantiation, if any.

Suggested resolution:

Change [temp.inst] p16 as indicated:

There is an implementation-defined quantity that specifies the limit on the total depth of recursive instantiations ([implimits]), which could involve more than one template. ~The result of an infinite recursion in instantiation is undefined.~ An infinite recursion in instantiation makes the program ill-formed, no diagnostic required.

Drafting notes: This is possibly diagnosable because infinite recursion would require infinite resources for real-world implementations, which should result in predictable translation failure.

jensmaurer commented 1 year ago

CWG2776 covers this.