public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/47950] New: [C++0x] Internal compiler error: non-dependent declaration as condition causes tsubst_copy_and_build assertion failure.
@ 2011-03-02 11:21 dev.lists at jessamine dot co.uk
  2011-03-02 15:39 ` [Bug c++/47950] " dev.lists at jessamine dot co.uk
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: dev.lists at jessamine dot co.uk @ 2011-03-02 11:21 UTC (permalink / raw)
  To: gcc-bugs

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

           Summary: [C++0x] Internal compiler error: non-dependent
                    declaration as condition causes tsubst_copy_and_build
                    assertion failure.
           Product: gcc
           Version: 4.6.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: dev.lists@jessamine.co.uk


The following program demonstrates an assertion failure in
tsubst_copy_and_build when compiling in C++0x mode.

It may be related to bug 47808 which fails the same assertion via a different
route (looks like it's using a non-dependent constexpr function to determine
the size of an array).

This issue demonstrated here appears to manifest only when a non-dependent
declaration is used as a condition within a selection statement inside a
template -- and only then if the standard initializer syntax is used with the
rhs being a constructor or function call.

This was done using 4.6.0 20110302 built this morning.  Failures only occur in
C++0x mode.

This is a recent regression -- a build from a few days ago did not exhibit this
issue.


template <typename T> struct empty
{
   // allow success case to build (not relevant to bug)
   operator bool() { return true; }
};

template <typename T> struct from_int
{
   from_int(int) {}

   // allow success case to build (not relevant to bug)
   operator bool() { return true; }
};

template <typename T>
from_int<T> via_function(T v)
{
   return from_int<T>(v);
}

template <typename T>
void f()
{
   // ********* this section compiles ***********

   // these plain initializers work fine
   from_int<int> a = 7;
   from_int<int> b = from_int<int>(7);
   empty<int>    c = empty<int>();
   from_int<T> ta = 7;
   from_int<T> tb = from_int<T>(7);
   empty<T>    tc = empty<T>();

   // these dependent condition decls work fine
   if (empty<T> x = empty<T>())
      ;
   if (from_int<T> x = 7)
      ;
   if (from_int<T> x = from_int<T>(7))
      ;
   if (from_int<T> x = via_function(T()))
      ;

   // this non-dependent condition decl using conversion works fine
   if (from_int<int> x = 7)
      ;

   // these non-dependent condition decls using conversion or braced-
   // initialization work fine (in c++0x mode only course)
   #if __GXX_EXPERIMENTAL_CXX0X__
   if (empty<int> x {})
      ;
   if (from_int<int> x {7})
      ;
   #endif

   // ********** this section fails in C++0x ***********

   // the following non-dependent condition decls cause an assertion
   // failure in
   //
   //   tsubst_copy_and_build, at cp/pt.c:13370
   //
   // in C++0x mode
   //
   if (empty<int> x = empty<int>())
      ;
   if (from_int<int> x = from_int<int>(7))
      ;
   if (from_int<int> x = via_function(7))
      ;
}

int main()
{
   f<int>();
}


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

* [Bug c++/47950] [C++0x] Internal compiler error: non-dependent declaration as condition causes tsubst_copy_and_build assertion failure.
  2011-03-02 11:21 [Bug c++/47950] New: [C++0x] Internal compiler error: non-dependent declaration as condition causes tsubst_copy_and_build assertion failure dev.lists at jessamine dot co.uk
@ 2011-03-02 15:39 ` dev.lists at jessamine dot co.uk
  2011-03-02 16:08 ` [Bug c++/47950] [4.6 Regression] " redi at gcc dot gnu.org
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: dev.lists at jessamine dot co.uk @ 2011-03-02 15:39 UTC (permalink / raw)
  To: gcc-bugs

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

Adam Butcher <dev.lists at jessamine dot co.uk> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |dev.lists at jessamine dot
                   |                            |co.uk, jason at gcc dot
                   |                            |gnu.org

--- Comment #1 from Adam Butcher <dev.lists at jessamine dot co.uk> 2011-03-02 15:39:00 UTC ---
Added Jason to CC.

Rolling back to my previous HEAD reveals that the reduced example above still
fails whereas the code I was originally trying to build worked.  So obviously
my reduction has changed something.  It doesn't change the fact that there is
an internal compiler error with the example above but it does mean that maybe
it is less likely to be hit.

So I was wrong that the above code has regressed in the last few days.  The
code that I was originally trying to build, which did work a few days ago and
now fails with the symptoms described above was using BOOST_FOREACH.  Obviously
this is unnecessary in C++0x as there is for(:) but it was compiling fine
before (and does in an old GCC 4.5 I have in C++0x mode).

The boost example was a non-dependent boost.foreach in a function template:

  #include <vector>
  #include <boost/foreach.hpp>

  template <typename T>
  void f()
  {
     std::vector<int> v = { 1,2,3,4 };
     BOOST_FOREACH(int x, v)
     {
     }
  }

  int main()
  {
     f<int>();
  }

Making the vector dependent on T rather than int makes the problem go away.  I
arrived at the reduction stated previously by breaking down BOOST_FOREACH until
the failure occurred.

Clearly there is an issue here but I'll do a bit more investigation into why
the boost example worked a few builds ago and why my reduction doesn't.


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

* [Bug c++/47950] [4.6 Regression] [C++0x] Internal compiler error: non-dependent declaration as condition causes tsubst_copy_and_build assertion failure.
  2011-03-02 11:21 [Bug c++/47950] New: [C++0x] Internal compiler error: non-dependent declaration as condition causes tsubst_copy_and_build assertion failure dev.lists at jessamine dot co.uk
  2011-03-02 15:39 ` [Bug c++/47950] " dev.lists at jessamine dot co.uk
@ 2011-03-02 16:08 ` redi at gcc dot gnu.org
  2011-03-02 16:30 ` dev.lists at jessamine dot co.uk
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: redi at gcc dot gnu.org @ 2011-03-02 16:08 UTC (permalink / raw)
  To: gcc-bugs

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

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |ice-on-valid-code
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2011.03.02 16:07:53
            Summary|[C++0x] Internal compiler   |[4.6 Regression] [C++0x]
                   |error: non-dependent        |Internal compiler error:
                   |declaration as condition    |non-dependent declaration
                   |causes                      |as condition causes
                   |tsubst_copy_and_build       |tsubst_copy_and_build
                   |assertion failure.          |assertion failure.
     Ever Confirmed|0                           |1

--- Comment #2 from Jonathan Wakely <redi at gcc dot gnu.org> 2011-03-02 16:07:53 UTC ---
(In reply to comment #1)
> So I was wrong that the above code has regressed in the last few days.

Confirmed, it fails with 4.6.0 20110219 too, but not in c++98 mode or with 4.5


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

* [Bug c++/47950] [4.6 Regression] [C++0x] Internal compiler error: non-dependent declaration as condition causes tsubst_copy_and_build assertion failure.
  2011-03-02 11:21 [Bug c++/47950] New: [C++0x] Internal compiler error: non-dependent declaration as condition causes tsubst_copy_and_build assertion failure dev.lists at jessamine dot co.uk
  2011-03-02 15:39 ` [Bug c++/47950] " dev.lists at jessamine dot co.uk
  2011-03-02 16:08 ` [Bug c++/47950] [4.6 Regression] " redi at gcc dot gnu.org
@ 2011-03-02 16:30 ` dev.lists at jessamine dot co.uk
  2011-03-02 22:46 ` jason at gcc dot gnu.org
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: dev.lists at jessamine dot co.uk @ 2011-03-02 16:30 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from Adam Butcher <dev.lists at jessamine dot co.uk> 2011-03-02 16:30:30 UTC ---
(In reply to comment #1)
> 
> Rolling back to my previous HEAD reveals that the reduced example above still
> fails whereas the code I was originally trying to build worked.  So obviously
> my reduction has changed something.
>
Okay.  My original reduction was okay but I also added additional examples that
yielded the same assertion failure (obviously via different route!).  The
function-call case following is the one that causes the failure in
non-dependent use of boost.foreach on the latest 4.6 HEAD.  It compiles okay on
my 4.6 build from last week (prior to 170488).

   if (from_int<int> x = via_function(7))
      ;

The constructor cases below have failed for a much longer time (though are okay
in 4.5). 

   if (empty<int> x = empty<int>())
      ;
   if (from_int<int> x = from_int<int>(7))
      ;

So the only recent regression is the function-call case.  But all cases are all
still legitimate 4.5 -> 4.6 regressions.

Before rev 170488 (25th Feb) the function-call case compiled.

I don't know when the constructor cases stopped working -- I went quite a way
back and they still failed.


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

* [Bug c++/47950] [4.6 Regression] [C++0x] Internal compiler error: non-dependent declaration as condition causes tsubst_copy_and_build assertion failure.
  2011-03-02 11:21 [Bug c++/47950] New: [C++0x] Internal compiler error: non-dependent declaration as condition causes tsubst_copy_and_build assertion failure dev.lists at jessamine dot co.uk
                   ` (2 preceding siblings ...)
  2011-03-02 16:30 ` dev.lists at jessamine dot co.uk
@ 2011-03-02 22:46 ` jason at gcc dot gnu.org
  2011-03-03  2:49 ` jason at gcc dot gnu.org
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: jason at gcc dot gnu.org @ 2011-03-02 22:46 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |ASSIGNED


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

* [Bug c++/47950] [4.6 Regression] [C++0x] Internal compiler error: non-dependent declaration as condition causes tsubst_copy_and_build assertion failure.
  2011-03-02 11:21 [Bug c++/47950] New: [C++0x] Internal compiler error: non-dependent declaration as condition causes tsubst_copy_and_build assertion failure dev.lists at jessamine dot co.uk
                   ` (3 preceding siblings ...)
  2011-03-02 22:46 ` jason at gcc dot gnu.org
@ 2011-03-03  2:49 ` jason at gcc dot gnu.org
  2011-03-03  8:47 ` dev.lists at jessamine dot co.uk
  2011-03-03 16:51 ` jason at gcc dot gnu.org
  6 siblings, 0 replies; 8+ messages in thread
From: jason at gcc dot gnu.org @ 2011-03-03  2:49 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from Jason Merrill <jason at gcc dot gnu.org> 2011-03-03 02:49:30 UTC ---
Author: jason
Date: Thu Mar  3 02:49:28 2011
New Revision: 170639

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=170639
Log:
    PR c++/47950
    * parser.c (cp_parser_condition): Don't fold_non_dependent_expr here.

Added:
    trunk/gcc/testsuite/g++.dg/cpp0x/regress/condition1.C
Modified:
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/parser.c
    trunk/gcc/testsuite/ChangeLog


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

* [Bug c++/47950] [4.6 Regression] [C++0x] Internal compiler error: non-dependent declaration as condition causes tsubst_copy_and_build assertion failure.
  2011-03-02 11:21 [Bug c++/47950] New: [C++0x] Internal compiler error: non-dependent declaration as condition causes tsubst_copy_and_build assertion failure dev.lists at jessamine dot co.uk
                   ` (4 preceding siblings ...)
  2011-03-03  2:49 ` jason at gcc dot gnu.org
@ 2011-03-03  8:47 ` dev.lists at jessamine dot co.uk
  2011-03-03 16:51 ` jason at gcc dot gnu.org
  6 siblings, 0 replies; 8+ messages in thread
From: dev.lists at jessamine dot co.uk @ 2011-03-03  8:47 UTC (permalink / raw)
  To: gcc-bugs

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

Adam Butcher <dev.lists at jessamine dot co.uk> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
         Resolution|                            |FIXED

--- Comment #5 from Adam Butcher <dev.lists at jessamine dot co.uk> 2011-03-03 08:47:09 UTC ---
Great.  Full build of our tree works from clean with latest 4.6 HEAD now.


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

* [Bug c++/47950] [4.6 Regression] [C++0x] Internal compiler error: non-dependent declaration as condition causes tsubst_copy_and_build assertion failure.
  2011-03-02 11:21 [Bug c++/47950] New: [C++0x] Internal compiler error: non-dependent declaration as condition causes tsubst_copy_and_build assertion failure dev.lists at jessamine dot co.uk
                   ` (5 preceding siblings ...)
  2011-03-03  8:47 ` dev.lists at jessamine dot co.uk
@ 2011-03-03 16:51 ` jason at gcc dot gnu.org
  6 siblings, 0 replies; 8+ messages in thread
From: jason at gcc dot gnu.org @ 2011-03-03 16:51 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #6 from Jason Merrill <jason at gcc dot gnu.org> 2011-03-03 16:51:23 UTC ---
Author: jason
Date: Thu Mar  3 16:51:20 2011
New Revision: 170656

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=170656
Log:
    PR c++/47950
    * pt.c (tsubst_copy_and_build) [TARGET_EXPR]: Retain TREE_CONSTANT.

Modified:
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/pt.c


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

end of thread, other threads:[~2011-03-03 16:51 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-03-02 11:21 [Bug c++/47950] New: [C++0x] Internal compiler error: non-dependent declaration as condition causes tsubst_copy_and_build assertion failure dev.lists at jessamine dot co.uk
2011-03-02 15:39 ` [Bug c++/47950] " dev.lists at jessamine dot co.uk
2011-03-02 16:08 ` [Bug c++/47950] [4.6 Regression] " redi at gcc dot gnu.org
2011-03-02 16:30 ` dev.lists at jessamine dot co.uk
2011-03-02 22:46 ` jason at gcc dot gnu.org
2011-03-03  2:49 ` jason at gcc dot gnu.org
2011-03-03  8:47 ` dev.lists at jessamine dot co.uk
2011-03-03 16:51 ` 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).