public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/53821] New: [4.7.2,4.8 regression][c++11] multiple definitions of lambda
@ 2012-06-30 15:23 vincenzo.innocente at cern dot ch
  2012-06-30 15:33 ` [Bug c++/53821] " vincenzo.innocente at cern dot ch
                   ` (11 more replies)
  0 siblings, 12 replies; 13+ messages in thread
From: vincenzo.innocente at cern dot ch @ 2012-06-30 15:23 UTC (permalink / raw)
  To: gcc-bugs

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

             Bug #: 53821
           Summary: [4.7.2,4.8 regression][c++11] multiple definitions of
                    lambda
    Classification: Unclassified
           Product: gcc
           Version: 4.8.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: vincenzo.innocente@cern.ch


this is a regression as not happening in 4.6.2 and 4.7.1
I personally think that the template methods SHOULD be declared inline if
included in multiple sources…

anyhow since it was discussed at length  in PR53780 and PR53768
and got attention from developers I promised to reduce and post

cat inlT.cc
#include <algorithm>
template<typename T> struct Foo {

   virtual int bar(int,int);
   int k;
};

// int ebar(int,int) __attribute__ ((visibility ("default")));


template<typename T> 
int Foo<T>::bar(int i, int j) {
  auto ebar = [](int a, int b) { return a+b;};
  static int a=i;
  if (i>0) k = ebar(i,j);
  if (j>0) k = ebar(j,i);
  if (i>0) k = ebar(j,i);
  if (k>0) k = ebar(i,j);
  return (a==i) ? i : j;
}


struct A1 {

  Foo<float> * foo;

};


int __attribute__ ((visibility ("default")))  hello1 (int i, int j) { A1 a;
return a.foo->bar(i,j);} 

[vocms123] ~/public/ctest/bugs48 $ cat inlT2.cc
#include <algorithm>
template<typename T> struct Foo {

   virtual int bar(int,int);
   int k;
};

// int ebar(int,int) __attribute__ ((visibility ("default")));


template<typename T> 
int Foo<T>::bar(int i, int j) {
  auto ebar = [](int a, int b) { return a+b;};
  static int a=i;
  if (i>0) k = ebar(i,j);
  if (j>0) k = ebar(j,i);
  if (i>0) k = ebar(j,i);
  if (k>0) k = ebar(i,j);
  return (a==i) ? i : j;
}


struct A2 {

  Foo<float> * foo;

};

int __attribute__ ((visibility ("default")))  hello2 (int i, int j) { A2 a;
return a.foo->bar(i,j);} 


[vocms123] ~/public/ctest/bugs48 $ cat buildInlT
c++ -std=gnu++11 -O2 -fvisibility-inlines-hidden -fvisibility=hidden -flto -c
inlT.cc  -fPIC
c++ -std=gnu++11 -O2 -fvisibility-inlines-hidden -fvisibility=hidden -flto -c
inlT2.cc -fPIC
c++ -std=gnu++11 -O2 -fvisibility-inlines-hidden -fvisibility=hidden -flto
-shared inlT.o inlT2.o -fPIC -o inlT.so

source buildInlT
/afs/cern.ch/user/i/innocent/w3/gcc47slc5/bin/ld: error: inlT2.o: multiple
definition of 'Foo<float>::bar(int, int)::{lambda(int, int)#1}::_FUN(int, int)'
/afs/cern.ch/user/i/innocent/w3/gcc47slc5/bin/ld: inlT.o: previous definition
here
/afs/cern.ch/user/i/innocent/w3/gcc47slc5/bin/ld: error: inlT2.o: multiple
definition of 'Foo<float>::bar(int, int)::{lambda(int, int)#1}::operator int
(*)(int, int)() const'
/afs/cern.ch/user/i/innocent/w3/gcc47slc5/bin/ld: inlT.o: previous definition
here
collect2: error: ld returned 1 exit status

also with simpler
cat buildInlT0
c++ -std=gnu++11 -O2    -c inlT.cc  -fPIC
c++ -std=gnu++11 -O2    -c inlT2.cc -fPIC
c++ -std=gnu++11 -O2    -shared inlT.o inlT2.o -fPIC -o inlT.so
 source buildInlT0
/afs/cern.ch/user/i/innocent/w3/gcc47slc5/bin/ld: error: inlT2.o: multiple
definition of 'Foo<float>::bar(int, int)::{lambda(int, int)#1}::_FUN(int, int)'
/afs/cern.ch/user/i/innocent/w3/gcc47slc5/bin/ld: inlT.o: previous definition
here
/afs/cern.ch/user/i/innocent/w3/gcc47slc5/bin/ld: error: inlT2.o: multiple
definition of 'Foo<float>::bar(int, int)::{lambda(int, int)#1}::operator int
(*)(int, int)() const'
/afs/cern.ch/user/i/innocent/w3/gcc47slc5/bin/ld: inlT.o: previous definition
here


c++ -v
Using built-in specs.
COLLECT_GCC=c++
COLLECT_LTO_WRAPPER=/afs/cern.ch/user/i/innocent/w3/gcc47slc5/libexec/gcc/x86_64-unknown-linux-gnu/4.7.2/lto-wrapper
Target: x86_64-unknown-linux-gnu
Configured with: ../gcc-4.7/configure --enable-languages=c,c++,fortran
--disable-multilib --enable-gold=yes --disable-nls --enable-lto
--with-mpc=/afs/cern.ch/cms/slc5_amd64_gcc470/external/gcc/4.7.0
--with-gmp=/afs/cern.ch/cms/slc5_amd64_gcc470/external/gcc/4.7.0
--with-mpfr=/afs/cern.ch/cms/slc5_amd64_gcc470/external/gcc/4.7.0
--prefix=/afs/cern.ch/user/i/innocent/w3/gcc47slc5
--with-build-time-tools=/build/ge/new-binutils/a/slc5_amd64_gcc470/external/gcc/4.7.0-cms/bin
Thread model: posix
gcc version 4.7.2 20120629 (prerelease) [gcc-4_7-branch revision 189081] (GCC) 
[vocms123] ~/public/ctest/bugs48 $ ld -v
GNU gold (GNU Binutils 2.22.52.20120515) 1.11


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

end of thread, other threads:[~2012-12-06 14:40 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-06-30 15:23 [Bug c++/53821] New: [4.7.2,4.8 regression][c++11] multiple definitions of lambda vincenzo.innocente at cern dot ch
2012-06-30 15:33 ` [Bug c++/53821] " vincenzo.innocente at cern dot ch
2012-06-30 19:22 ` hjl.tools at gmail dot com
2012-07-02  8:53 ` [Bug c++/53821] [4.7/4.8 " rguenth at gcc dot gnu.org
2012-07-02 10:07 ` redi at gcc dot gnu.org
2012-07-02 19:15 ` jason at gcc dot gnu.org
2012-07-02 19:15 ` jason at gcc dot gnu.org
2012-07-02 19:26 ` jason at gcc dot gnu.org
2012-07-03 20:40 ` vincenzo.innocente at cern dot ch
2012-07-03 20:56 ` redi at gcc dot gnu.org
2012-07-03 21:28 ` jason at gcc dot gnu.org
2012-12-06 14:38 ` jason at gcc dot gnu.org
2012-12-06 14:40 ` 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).