[Bug 1491643] Re: Construction failure of a POD through a constexpr function if called in a template function
Matthias Klose
doko at ubuntu.com
Wed Mar 30 12:57:34 UTC 2016
fixed in 16.04
** Changed in: gcc-5 (Ubuntu)
Status: New => Fix Released
--
You received this bug notification because you are a member of Ubuntu
Foundations Bugs, which is subscribed to gcc-5 in Ubuntu.
https://bugs.launchpad.net/bugs/1491643
Title:
Construction failure of a POD through a constexpr function if called
in a template function
Status in gcc:
Unknown
Status in gcc-5 package in Ubuntu:
Fix Released
Bug description:
The following does not compile with 5.2.1 (20150825) and 6.0.0 (20150825).
Ok with 4.9.3 and clang++ (3.5 and 3.6).
#include <array>
#include <utility>
struct Pos
{
unsigned l,c,a;
//fix g++
// constexpr Pos(unsigned l, unsigned c, unsigned a)
// : l(l), c(c), a(a)
// {}
};
template<class T, T... Ints>
constexpr std::array<Pos, 9*9> make_grid_position(std::integer_sequence<T, Ints...>)
{
return std::array<Pos, 9*9>{Pos{Ints / 9, Ints % 9, (Ints / 9) / 3 * 3 + (Ints % 9) / 3}...};
}
constexpr std::array<Pos, 9*9> make_grid_positions()
{
return make_grid_position(std::make_index_sequence<9*9>{});
}
template<class T>
void generate_sudoku(T)
{
constexpr std::array<Pos, 9*9> positions = make_grid_positions(); // fail
}
int main()
{
constexpr std::array<Pos, 9*9> positions = make_grid_positions(); // ok
generate_sudoku(1);
}
error:
std::array<Pos, 81ul>{std::__array_traits<Pos, 81ul>::_Type{Pos{0u, 0u, 0u}, Pos{0u, 1u, 0u}, Pos{0u, 2u, 0u}, Pos{0u, 3u, 1u}, Pos{0u, 4u, 1u}, Pos{0u, 5u, 1u}, Pos{0u, 6u, 2u}, Pos{0u, 7u, 2u}, Pos{0u, 8u, 2u}, Pos{1u, 0u, 0u}, Pos{1u, 1u, 0u}, Pos{1u, 2u, 0u}, Pos{1u, 3u, 1u}, Pos{1u, 4u, 1u}, Pos{1u, 5u, 1u}, Pos{1u, 6u, 2u}, Pos{1u, 7u, 2u}, Pos{1u, 8u, 2u},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oku isn't a template, it compiles.
g++-5 -std=c++14 -v
Using built-in specs.
COLLECT_GCC=g++-5
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/5/lto-wrapper
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu 5.2.1-15ubuntu5' --with-bugurl=file:///usr/share/doc/gcc-5/README.Bugs --enable-languages=c,ada,c++,java,go,d,fortran,objc,obj-c++ --prefix=/usr --program-suffix=-5 --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-vtable-verify --enable-libmpx --enable-plugin --with-system-zlib --disable-browser-plugin --enable-java-awt=gtk --enable-gtk-cairo --with-java-home=/usr/lib/jvm/java-1.5.0-gcj-5-amd64/jre --enable-java-home --with-jvm-root-dir=/usr/lib/jvm/java-1.5.0-gcj-5-amd64 --with-jvm-jar-dir=/usr/lib/jvm-exports/java-1.5.0-gcj-5-amd64 --with-arch-directory=amd64 --with-ecj-jar=/usr/share/java/eclipse-ecj.jar --enable-objc-gc --enable-multiarch --disable-werror --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
gcc version 5.2.1 20150825 (Ubuntu 5.2.1-15ubuntu5)
To manage notifications about this bug go to:
https://bugs.launchpad.net/gcc/+bug/1491643/+subscriptions
More information about the foundations-bugs
mailing list