Title
Checking of default template arguments
Status
dr
Section
13.8.1 [temp.res.general]
Submitter
Shafik Yaghmour

Created on 2023-06-07.00:00:00 last changed 3 weeks ago

Messages

Date: 2024-03-20.04:45:01

Proposed resolution (approved by CWG 2024-03-01):

Change in 13.8.1 [temp.res.general] paragraph 6 as follows:

The validity of a template may be checked prior to any instantiation. [Note : ... —end note]

The program is ill-formed, no diagnostic required, if:

  • no valid specialization, ignoring static_assert-declarations that fail, can be generated for a template or a substatement of a constexpr if statement (8.5.2 [stmt.if]) within a template and the template is not instantiated, or
  • no valid specialization, ignoring static_assert-declarations that fail, can be generated for a default template-argument and the default template-argument is not used in any instantiation, or
  • any constraint-expression in the program, introduced or otherwise, has (in its normal form) an atomic constraint A where no satisfaction check of A could be well-formed and no satisfaction check of A is performed, or
  • every valid specialization of a variadic template requires an empty template parameter pack, or
  • a hypothetical instantiation of a template immediately following its definition would be ill-formed due to a construct that does not depend on a template parameter, or
  • the interpretation of such a construct in the hypothetical instantiation is different from the interpretation of the corresponding construct in any actual instantiation of the template.
Date: 2024-03-15.00:00:00

[Accepted as a DR at the March, 2024 meeting.]

Consider:

  static int x = 1;
  template<auto y = x> void f() {}

Is the definition of f well-formed? Since x is not a constant expression, any use of the default template argument is ill-formed, but for example f<5>() does not actually use it.

Are implementations allowed or required to reject this situation, even if the template is never instantiated? If the default template argument is dependent, checking may need to be deferred to instantiations in any case.

History
Date User Action Args
2024-04-05 21:43:46adminsetstatus: ready -> dr
2024-03-20 04:45:01adminsetstatus: tentatively ready -> ready
2024-03-03 21:57:08adminsetmessages: + msg7628
2024-03-03 21:57:08adminsetstatus: open -> tentatively ready
2023-06-07 00:00:00admincreate