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

             Bug #: 54557
           Summary: [c++ lambda] error in assigning lambda expr though
                    "operator?:" while catching
    Classification: Unclassified
           Product: gcc
           Version: 4.8.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassig...@gcc.gnu.org
        ReportedBy: vincenzo.innoce...@cern.ch


in this example
foo1 and foo2 do not compile, bar and foo3 do.


cat  iflamda.cc
struct A {

int q;
bool sel;
  bool bar(int i, int j) const;
  bool foo1(int i, int j) const;
  bool foo2(int i, int j) const;
  bool foo3(int i, int j) const;

};


bool A:: bar(int i, int j) const {
  auto f = sel ? [](int a, int b) { return a<b;} :
                 [](int a, int b) { return b<a;};

  return f(i,j);
}



bool A::foo1(int i, int j) const {
  auto f = sel ? [this](int a, int b) { return a<b;} :
                 [this](int a, int b) { return a<b+this->q;};

  return f(i,j);
}


bool A::foo2(int i, int j) const {
  int k = q;
  auto f = sel ? [k](int a, int b) { return a<b;} :
                 [k](int a, int b) { return a<b+k;};

  return f(i,j);
}

bool A::foo3(int i, int j) const {
  auto f = sel ? [](int a, int b,int) { return a<b;} :
                 [](int a, int b, int k) { return a<b+k;};

  return f(i,j,q);
}


Vincenzos-MacBook-Pro:ctest innocent$ c++ -O2 -std=gnu++11 -c iflamda.cc 
iflamda.cc: In member function ‘bool A::foo1(int, int) const’:
iflamda.cc:24:60: error: no match for ternary ‘operator?:’ (operand types are
‘bool’, ‘A::foo1(int, int) const::__lambda2’, and ‘A::foo1(int, int)
const::__lambda3’)
                  [this](int a, int b) { return a<b+this->q;};
                                                            ^
iflamda.cc: In member function ‘bool A::foo2(int, int) const’:
iflamda.cc:33:51: error: no match for ternary ‘operator?:’ (operand types are
‘bool’, ‘A::foo2(int, int) const::__lambda4’, and ‘A::foo2(int, int)
const::__lambda5’)
                  [k](int a, int b) { return a<b+k;};
                                                   ^
Vincenzos-MacBook-Pro:ctest innocent$ c++ -v
Using built-in specs.
COLLECT_GCC=c++
COLLECT_LTO_WRAPPER=/usr/local/libexec/gcc/x86_64-apple-darwin12.1.0/4.8.0/lto-wrapper
Target: x86_64-apple-darwin12.1.0
Configured with: ./configure --enable-languages=c,c++,fortran
--disable-multilib --disable-bootstrap --enable-lto -disable-libitm
Thread model: posix
gcc version 4.8.0 20120912 (experimental) [trunk revision 191215] (GCC)

Reply via email to