Bug 105808 - Internal unsafe integer narrowing conversion during non-type template argument value deduction
Summary: Internal unsafe integer narrowing conversion during non-type template argumen...
Status: UNCONFIRMED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 11.2.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: diagnostic
Depends on:
Blocks:
 
Reported: 2022-06-01 20:00 UTC by Anatoliy Tomilov
Modified: 2022-06-01 21:40 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments
test.cpp (175 bytes, text/plain)
2022-06-01 20:00 UTC, Anatoliy Tomilov
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Anatoliy Tomilov 2022-06-01 20:00:06 UTC
Created attachment 53064 [details]
test.cpp

GCC version: G++ 11.2.0
system type: Linux 5.10.105-1-MANJARO Mar 2022 x86_64 GNU/Linux

g++ -m64 -Wall -Wextra -c test.cpp -o /dev/null

No warning or errors reported (except static_assert violation).

Affected std::extent and std::extent_v for big arrays.
-mcmodel=medium has no effect.
Comment 1 Andrew Pinski 2022-06-01 20:17:24 UTC
Removing the include:
using size_t = decltype(sizeof(0));

template<typename>
struct extent
{
    static constexpr size_t value = 0;
};

template<typename T, size_t size>
struct extent<T[size]>
{
    static constexpr size_t value = size;
};

static_assert(extent<char[1ULL << 32]>::value != 0, "");  // fails
----- CUT ----

GCC 7 and before used to error out about the overflow:
<source>: In substitution of 'template<class T, long unsigned int size> struct extent<T [size]> [with T = char; long unsigned int size = 0]':
<source>:15:39:   required from here
<source>:15:39: error: overflow in constant expression
 static_assert(extent<char[1ULL << 32]>::value != 0, "");  // fails
                                       ^~

clang accepts the code as being valid ...