[Bug 258079] clang-11 fails: candidate template ignored: substitution failure [with U = float]: variable length array cannot be formed during template argument deduction

From: <bugzilla-noreply_at_freebsd.org>
Date: Fri, 27 Aug 2021 10:12:09 UTC
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=258079

David Chisnall <theraven@FreeBSD.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |Works As Intended
             Status|New                         |Closed
                 CC|                            |theraven@FreeBSD.org

--- Comment #4 from David Chisnall <theraven@FreeBSD.org> ---
The code in the test case contains undefined behaviour.  `IntBits` is 64 - 20,
whcih is 44.  `1U` is an `unsigned int`, which is 32 bits.  `1U<<44` is a shift
of greater than the width od the type, which is undefined behaviour.

This is *probably* benign here, because array sizes in arguments in C/C++ are
ignored and so this probably won't propagate into the generated IR (though if
it does, both clang and GCC will take advantage of the UB and probably reduce
this to something that traps.

The correct fix is to change `1U` to `1ULL`.  Rejecting code that contains
undefined behaviour is both allowed by the standard and generally considered
more user-friendly behaviour than accepting it and generating broken code.

-- 
You are receiving this mail because:
You are the assignee for the bug.