gcc 4.7.3-1ubuntu10 c++11 bogus errors (reduced, not reproducible upstream)

Bug #1172951 reported by Andy Lutomirski
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
gcc
Fix Released
Medium
gcc-4.7 (Ubuntu)
Confirmed
Medium
Unassigned

Bug Description

This code:

namespace NS {

struct A
{
  static void foo(int);

  template<typename Func>
  void func(Func f)
  {
    [&](){
      do {
 do {
   if (1)
     foo(0);
 } while(0);
      } while (0);
    };
  }
};

}

void caller()
{
  NS::A a;
  a.func([&]{});
}

Fails like this on Raring:

redeclaration_bug.cc: In instantiation of 'NS::A::func(Func) [with Func = caller()::<lambda()>]::<lambda()>':
redeclaration_bug.cc:14:11: required from 'struct NS::A::func(Func) [with Func = caller()::<lambda()>]::<lambda()>'
redeclaration_bug.cc:10:5: required from 'void NS::A::func(Func) [with Func = caller()::<lambda()>]'
redeclaration_bug.cc:26:15: required from here
redeclaration_bug.cc:14:11: error: redeclaration of 'NS::A* const NS::A::func(Func) [with Func = caller()::<lambda()>]::<lambda()>::__this'
redeclaration_bug.cc:14:11: note: previous declaration 'NS::A* const NS::A::func(Func) [with Func = caller()::<lambda()>]::<lambda()>::__this'
redeclaration_bug.cc:14:11: error: redeclaration of 'NS::A* const this'
redeclaration_bug.cc:14:11: error: 'NS::A* const this' previously declared here
redeclaration_bug.cc: In instantiation of 'void NS::A::func(Func) [with Func = caller()::<lambda()>]':
redeclaration_bug.cc:26:15: required from here
redeclaration_bug.cc:10:5: error: too many initializers for 'NS::A::func(Func) [with Func = caller()::<lambda()>]::<lambda()>'

It compiles fine on Fedora 18's gcc 4.7.2 as well as a version of the upstream 4.7 branch that I just built today. (The latter calls itself 4.7.4.)

Revision history for this message
In , Omawarisan-bokudesu (omawarisan-bokudesu) wrote :

"g++ -std=c++11" rejects the following program:

int main()
{
    bool /*const*/ condition = false;

    [&]{
        try{}
        catch(...){
            if(condition){}
        }
    }();
}

If the condition variable is const, the compilation successes.

Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=/home/user/gcc-trunk/libexec/gcc/x86_64-unknown-linux-gnu/4.8.0/lto-wrapper
Target: x86_64-unknown-linux-gnu
Configured with: ../gcc/configure --prefix=/home/user/gcc-trunk --disable-bootstrap --disable-multilib --enable-languages=c,c++,fortran --with-gmp=/home/user/gcc-trunk/src/build/backends --with-mpfr=/home/user/gcc-trunk/src/build/backends --with-mpc=/home/user/gcc-trunk/src/build/backends
Thread model: posix
gcc version 4.8.0 20130219 (experimental) (GCC)

Revision history for this message
In , Daniel-kruegler (daniel-kruegler) wrote :

The problem also exists for 4.7.2, so no regression. The diagnostics is interesting:

"7:9: error: '...' handler must be the last handler for its try block [-fpermissive]
catch(...){
^"

Revision history for this message
In , Jason-gcc (jason-gcc) wrote :

It's a regression from 4.6.

Revision history for this message
In , Jason-gcc (jason-gcc) wrote :

Fixed for 4.7.4/4.8.1/4.9.0.

Revision history for this message
Andy Lutomirski (luto-mit) wrote :

I think this is c++/56388 upstream. r198010 on the 4.7 branch seems to fix it.

Matthias Klose (doko)
affects: gcc-defaults (Ubuntu) → gcc-4.7 (Ubuntu)
Changed in gcc-4.7 (Ubuntu):
importance: Undecided → Medium
status: New → Confirmed
Changed in gcc:
importance: Unknown → Medium
status: Unknown → Fix Released
Revision history for this message
In , Paolo-carlini (paolo-carlini) wrote :

*** Bug 57143 has been marked as a duplicate of this bug. ***

Revision history for this message
In , Paolo-carlini (paolo-carlini) wrote :

*** Bug 57995 has been marked as a duplicate of this bug. ***

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.