I have this example code
#include <iostream>
#include <array>
#include <bitset>
template <class T, std::size_t N>
class Booth
{
public:
int function(const std::array<T, N> & data) {
std::bitset<data.size()> bit_set{};
return 0;
};
private:
};
int main()
{
std::cout << "std::array test\n";
std::array<int, 3> data2{2};
Booth<int, 3>booth{};
std::cout << booth.function(data2) << std::endl;
return 0;
}
It compiles fine in [OnlineGDB][1]
. And in the older versions of gcc
. However, it started failing in gcc
11:
g++ -Wall -Wconversion -lstdc++ -pthread -std=c++17 -o array_size src/array_size.cpp
src/array_size.cpp: In function ‘int function(const std::array<int, 42>&)’:
src/array_size.cpp:22:28: error: ‘data’ is not a constant expression
22 | std::bitset<data.size()> bit_set{};
| ^
src/array_size.cpp:22:26: note: in template argument for type ‘long unsigned int’
22 | std::bitset<data.size()> bit_set{};
| ~~~~~~~~~^~
The code is the same. The language version is the same. I know how to fix this error. I just would like to know what was changed in the compiler? What is the reason for this change and thus the failure?