https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103595

            Bug ID: 103595
           Summary: [11 Regression] std::function parameter with default
                    value lambda, fails with error redefinition of 'const
                    char _ZT... []'
           Product: gcc
           Version: 11.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: mortenkschou at gmail dot com
  Target Milestone: ---

Created attachment 51936
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=51936&action=edit
preprocessed source

A (templated) function takes a const std::function& as a parameter with a
lambda as the default value. When this function is called from two separate
places (in a certain way and order) gcc-11 fails with the following error:

bug.cpp:12:1: error: redefinition of ‘const char
_ZTSZN1AIiE3fooES0_RKSt8functionIFvvEEEd_UlvE_ []’
   12 | }
      | ^
bug.cpp:12:1: note: ‘const char _ZTSZN1AIiE3fooES0_RKSt8functionIFvvEEEd_UlvE_
[43]’ previously defined here


See minimal code example (https://godbolt.org/z/Mqs1Mbb1z)
#include <functional>
template<typename T> class A {
public:
    void foo(A<T> a, const std::function<void()>& fn = [](){}) { }
    void bar(A<T> a) { foo(a); }
};
int main() {
    A<int> a;
    a.foo(a);
    a.bar(a);
    return 0;
}

This code compiles (according to godbolt.org) on gcc-10.3 and prior as well as
clang and MSVC, but fails on gcc-11.x. 
Note that calling bar before foo compiles successfully on gcc-11.

I don't know if this is a compiler error, an error in <function>
implementation, or a violation of the C++ standard.? But my bet would be on a
compiler error.


Full compilation output. (Also .ii file in attachment)

$ gcc -v --save-temp bug.cpp 
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/11/lto-wrapper
OFFLOAD_TARGET_NAMES=nvptx-none:amdgcn-amdhsa
OFFLOAD_TARGET_DEFAULT=1
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu 11.2.0-7ubuntu2'
--with-bugurl=file:///usr/share/doc/gcc-11/README.Bugs
--enable-languages=c,ada,c++,go,brig,d,fortran,objc,obj-c++,m2 --prefix=/usr
--with-gcc-major-version-only --program-suffix=-11
--program-prefix=x86_64-linux-gnu- --enable-shared --enable-linker-build-id
--libexecdir=/usr/lib --without-included-gettext --enable-threads=posix
--libdir=/usr/lib --enable-nls --enable-bootstrap --enable-clocale=gnu
--enable-libstdcxx-debug --enable-libstdcxx-time=yes
--with-default-libstdcxx-abi=new --enable-gnu-unique-object
--disable-vtable-verify --enable-plugin --enable-default-pie --with-system-zlib
--enable-libphobos-checking=release --with-target-system-zlib=auto
--enable-objc-gc=auto --enable-multiarch --disable-werror --enable-cet
--with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32
--enable-multilib --with-tune=generic
--enable-offload-targets=nvptx-none=/build/gcc-11-ZPT0kp/gcc-11-11.2.0/debian/tmp-nvptx/usr,amdgcn-amdhsa=/build/gcc-11-ZPT0kp/gcc-11-11.2.0/debian/tmp-gcn/usr
--without-cuda-driver --enable-checking=release --build=x86_64-linux-gnu
--host=x86_64-linux-gnu --target=x86_64-linux-gnu
--with-build-config=bootstrap-lto-lean --enable-link-serialization=2
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 11.2.0 (Ubuntu 11.2.0-7ubuntu2) 
COLLECT_GCC_OPTIONS='-v' '-save-temps' '-mtune=generic' '-march=x86-64'
'-dumpdir' 'a-'
 /usr/lib/gcc/x86_64-linux-gnu/11/cc1plus -E -quiet -v -imultiarch
x86_64-linux-gnu -D_GNU_SOURCE bug.cpp -mtune=generic -march=x86-64
-fpch-preprocess -fasynchronous-unwind-tables -fstack-protector-strong -Wformat
-Wformat-security -fstack-clash-protection -fcf-protection -o a-bug.ii
ignoring duplicate directory "/usr/include/x86_64-linux-gnu/c++/11"
ignoring nonexistent directory "/usr/local/include/x86_64-linux-gnu"
ignoring nonexistent directory "/usr/lib/gcc/x86_64-linux-gnu/11/include-fixed"
ignoring nonexistent directory
"/usr/lib/gcc/x86_64-linux-gnu/11/../../../../x86_64-linux-gnu/include"
#include "..." search starts here:
#include <...> search starts here:
 /usr/include/c++/11
 /usr/include/x86_64-linux-gnu/c++/11
 /usr/include/c++/11/backward
 /usr/lib/gcc/x86_64-linux-gnu/11/include
 /usr/local/include
 /usr/include/x86_64-linux-gnu
 /usr/include
End of search list.
COLLECT_GCC_OPTIONS='-v' '-save-temps' '-mtune=generic' '-march=x86-64'
'-dumpdir' 'a-'
 /usr/lib/gcc/x86_64-linux-gnu/11/cc1plus -fpreprocessed a-bug.ii -quiet
-dumpdir a- -dumpbase bug.cpp -dumpbase-ext .cpp -mtune=generic -march=x86-64
-version -fasynchronous-unwind-tables -fstack-protector-strong -Wformat
-Wformat-security -fstack-clash-protection -fcf-protection -o a-bug.s
GNU C++17 (Ubuntu 11.2.0-7ubuntu2) version 11.2.0 (x86_64-linux-gnu)
        compiled by GNU C version 11.2.0, GMP version 6.2.1, MPFR version
4.1.0, MPC version 1.2.0, isl version isl-0.24-GMP

GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
GNU C++17 (Ubuntu 11.2.0-7ubuntu2) version 11.2.0 (x86_64-linux-gnu)
        compiled by GNU C version 11.2.0, GMP version 6.2.1, MPFR version
4.1.0, MPC version 1.2.0, isl version isl-0.24-GMP

GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
Compiler executable checksum: b2aa013a9bb78f98e29ce58cd37c6337
bug.cpp:12:1: error: redefinition of ‘const char
_ZTSZN1AIiE3fooES0_RKSt8functionIFvvEEEd_UlvE_ []’
   12 | }
      | ^
bug.cpp:12:1: note: ‘const char _ZTSZN1AIiE3fooES0_RKSt8functionIFvvEEEd_UlvE_
[43]’ previously defined here

Reply via email to