Issue 181747
Summary -Wconstant-conversion missing out-of-range integral constant in NTTP and template initialization
Labels new issue
Assignees
Reporter Stee-T
    **Description**

`-Wconstant-conversion` does not emit a diagnostic when an integer constant outside the representable range of an integral is used as a non-type template parameter (NTTP) value.

This includes both default template arguments and explicit template arguments.

Although the program is well-formed C++ (the value is reduced modulo the destination type), the same conversion *does* trigger a diagnostic in normal variable initialization. This suggests inconsistent diagnostic handling for identical constant conversions.

**1. Default non-type template parameter**

```cpp
#include <cstdint>

template < uint8_t N = 400 >
struct TOk {};
```

**Actual behavior**

No diagnostic is emitted with ```-Wconstant-conversion```

**Expected behavior**

A diagnostic indicating that the constant value cannot be represented in `uint8_t` (even though the program remains well-formed and the value is reduced modulo the type).

**2. Explicit template argument**

```cpp
template<unsigned char N>
struct S {};

S<400> s;     // no warning
```

**3. Control example — equivalent initialization does warn**

```cpp
unsigned char x = 400;   // warning emitted here
```

This shows the same constant conversion is diagnosed in a normal initialization context but not when performed as part of template argument checking.
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to