cplusplus / CWG

Core Working Group
23 stars 7 forks source link

CWG2810 [temp.res.general] Templates should not silence diagnostics #428

Closed Eisenwave closed 3 months ago

Eisenwave commented 9 months ago

Reflector thread: https://lists.isocpp.org/core/2022/01/11929.php

Reference (section label): [temp.res.general]

Issue Description

In [temp.res.general] p6, it is stated that the program is ill-formed, no diagnostic required as the result of invalid constructs in templates, and:

Otherwise, no diagnostic shall be issued for a template for which a valid specialization can be generated.

The latter sentence serves no apparent purpose because the reader would not expect a diagnostic to be required if the program does not violate any of the listed conditions. Furthermore, it could be misinterpreted to mean that diagnostic messages such as optional warnings are required to be suppressed:

template <int> int foo(float x) {
    return x; // warning: conversion from float to int [-Wconversion]
}

Issuing a -Wconversion warning in this example could be seen as not conforming. Of course, an implementation could simply not treat -Wconversion as a diagnostic as per [defns.diagnostic]. However, this interpretation means that some warnings are diagnostics and some aren't, which is contrived, and complicated for the reader.

Suggested resolution

Update [temp.res.general] p6 as follows:

 [...]
-Otherwise, no diagnostic shall be issued for a template
-for which a valid specialization can be generated.
 [...]
Eisenwave commented 9 months ago

Note that I think that the intention of "implementation-defined subset" in [defns.diagnostic] is to say that informative messages or notes which are output aren't considered diagnostics; not to establish that only a subset of warnings or errors is a diagnostic.

It would mean that any implementation has to meticulously document which warning and error message is a diagnostic and which isn't, instead of being able to say that "warnings are diagnostics".

languagelawyer commented 9 months ago

Reflector thread https://lists.isocpp.org/core/2022/01/11929.php

jensmaurer commented 9 months ago

CWG2810