public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/49988] New: constexpr on ctor invokes improper initialization
@ 2011-08-05 12:27 faisalv at yahoo dot com
  2011-08-05 14:00 ` [Bug c++/49988] " faisalv at yahoo dot com
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: faisalv at yahoo dot com @ 2011-08-05 12:27 UTC (permalink / raw)
  To: gcc-bugs

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


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2011-08-06 22:25 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-08-05 12:27 [Bug c++/49988] New: constexpr on ctor invokes improper initialization faisalv at yahoo dot com
2011-08-05 14:00 ` [Bug c++/49988] " faisalv at yahoo dot com
2011-08-05 19:54 ` jason at gcc dot gnu.org
2011-08-06  4:34 ` jason at gcc dot gnu.org
2011-08-06  4:39 ` jason at gcc dot gnu.org
2011-08-06 22:25 ` jason at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).