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

* [Bug c++/49988] constexpr on ctor invokes improper initialization
  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 ` faisalv at yahoo dot com
  2011-08-05 19:54 ` jason at gcc dot gnu.org
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: faisalv at yahoo dot com @ 2011-08-05 14:00 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49988

--- Comment #1 from Faisal Vali <faisalv at yahoo dot com> 2011-08-05 13:59:55 UTC ---
Also, changing the parameter to a pointer to an array makes the code work
correctly:

struct A {
  char data[3];
    template<int ... I> 
    constexpr  
     // NOTE: now it is a pointer to an array - not just a pointer to char
    A(const char (*s)[3], X<I...> x) : data{ (*s)[I]...} { }

};


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

* [Bug c++/49988] constexpr on ctor invokes improper initialization
  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
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: jason at gcc dot gnu.org @ 2011-08-05 19:54 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49988

Jason Merrill <jason at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |ASSIGNED
   Last reconfirmed|                            |2011.08.05 19:53:43
         AssignedTo|unassigned at gcc dot       |jason at gcc dot gnu.org
                   |gnu.org                     |
     Ever Confirmed|0                           |1


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

* [Bug c++/49988] constexpr on ctor invokes improper initialization
  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
  4 siblings, 0 replies; 6+ messages in thread
From: jason at gcc dot gnu.org @ 2011-08-06  4:34 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49988

--- Comment #2 from Jason Merrill <jason at gcc dot gnu.org> 2011-08-06 04:34:25 UTC ---
Author: jason
Date: Sat Aug  6 04:34:21 2011
New Revision: 177496

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=177496
Log:
    PR c++/49988
    * semantics.c (cxx_eval_array_reference): Handle failure to
    reduce the array operand to something we can work with.

Added:
    trunk/gcc/testsuite/g++.dg/cpp0x/constexpr-non-const-arg3.C
Modified:
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/semantics.c
    trunk/gcc/testsuite/ChangeLog


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

* [Bug c++/49988] constexpr on ctor invokes improper initialization
  2011-08-05 12:27 [Bug c++/49988] New: constexpr on ctor invokes improper initialization faisalv at yahoo dot com
                   ` (2 preceding siblings ...)
  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
  4 siblings, 0 replies; 6+ messages in thread
From: jason at gcc dot gnu.org @ 2011-08-06  4:39 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49988

--- Comment #3 from Jason Merrill <jason at gcc dot gnu.org> 2011-08-06 04:38:11 UTC ---
Author: jason
Date: Sat Aug  6 04:38:08 2011
New Revision: 177500

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=177500
Log:
    PR c++/49988
    * semantics.c (cxx_eval_array_reference): Handle failure to
    reduce the array operand to something we can work with.

Added:
   
branches/gcc-4_6-branch/gcc/testsuite/g++.dg/cpp0x/constexpr-non-const-arg3.C
Modified:
    branches/gcc-4_6-branch/gcc/cp/ChangeLog
    branches/gcc-4_6-branch/gcc/cp/semantics.c
    branches/gcc-4_6-branch/gcc/testsuite/ChangeLog


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

* [Bug c++/49988] constexpr on ctor invokes improper initialization
  2011-08-05 12:27 [Bug c++/49988] New: constexpr on ctor invokes improper initialization faisalv at yahoo dot com
                   ` (3 preceding siblings ...)
  2011-08-06  4:39 ` jason at gcc dot gnu.org
@ 2011-08-06 22:25 ` jason at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: jason at gcc dot gnu.org @ 2011-08-06 22:25 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49988

Jason Merrill <jason at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
         Resolution|                            |FIXED
   Target Milestone|---                         |4.6.2

--- Comment #4 from Jason Merrill <jason at gcc dot gnu.org> 2011-08-06 22:24:03 UTC ---
Fixed for 4.6.2.


^ 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).