This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/49988] New: constexpr on ctor invokes improper initialization
- From: "faisalv at yahoo dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Fri, 5 Aug 2011 12:26:14 +0000
- Subject: [Bug c++/49988] New: constexpr on ctor invokes improper initialization
- Auto-submitted: auto-generated
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49988
Summary: constexpr on ctor invokes improper initialization
Product: gcc
Version: 4.6.1
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
AssignedTo: unassigned@gcc.gnu.org
ReportedBy: faisalv@yahoo.com
CC: jason@gcc.gnu.org
The following code compiles fine, but displays incorrect (or at the very least
inconsistent) behavior if constexpr is applied to A's ctor:
template<int ... I> struct X { };
struct A {
char data[3];
template<int ... I>
constexpr // works if you comment this constexpr out
A(const char (&s)[3], X<I...> x) : data{ s[I]...} { }
// above also works if you leave constexpr in but replace
// const char (&s)[3] with const char* s.
};
struct B {
A a;
B(const char (&s)[3]) : a{s,X<0,1,2>{}} { }
};
int main()
{
B b{"12"};
assert(b.a.data[0] == '1'); // assertion fails at run time
}
Compiled with gcc4.6.1 with *JUST* the following recent patch MANUALLY applied:
http://gcc.gnu.org/viewcvs/branches/gcc-4_6-branch/gcc/cp/semantics.c?r1=177188&r2=177187&pathrev=177188
(please refer to PR c++/49924 for details)
i.e gcc -v still reads (compared to PR c++/49924):
Using built-in specs.
COLLECT_GCC=g++-4.6.1
COLLECT_LTO_WRAPPER=/usr/local/gcc4.6.1/libexec/gcc/i686-pc-linux-gnu/4.6.1/lto-wrapper
Target: i686-pc-linux-gnu
Configured with: ../gcc-4.6.1/configure --prefix=/usr/local/gcc4.6.1
--enable-generated-files-in-srcdir --enable-threads=posix --with-system-zlib
--enable-__cxa_atexit --disable-checking --disable-nls --enable-bootstrap
--with-gcc --with-gnu-as --with-gnu-ld --disable-multilib
Thread model: posix
gcc version 4.6.1 (GCC)
I wonder if just applying that one patch manually, while fixing one bug, could
have introduced another?
Thanks