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

            Bug ID: 94115
           Summary: Wrong constructor called when 2 classes have the same
                    name
           Product: gcc
           Version: 9.2.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: cedric.chepied at delair dot aero
  Target Milestone: ---

Created attachment 48005
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=48005&action=edit
Source and ii files

When I create 2 classes with the same name in different cpp files and then
create 2 global variables (static const), the same constructor is called for
the
2 variables.  This only happens when compiling with -O0. With -O1 -O2 -O3 or
-Os
I can't see the problem.

test.cpp:
---------
#include <iostream>

class A {
public:
    A() {std::cout << "A test" << std::endl;}
};

static const A a;

int main() {
    return 0;
}


test2.cpp:
----------
#include <iostream>

class A {
public:
    A() {std::cout << "A test2" << std::endl;}
};

static const A b;

Compile command:
----------------
g++ -O0 -o test test.cpp test2.cpp

Expected result:
----------------
A test
A test2

Result with -O0:
----------------
A test
A test

gcc -v :
--------
Utilisation des specs internes.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-pc-linux-gnu/9.2.1/lto-wrapper
Cible : x86_64-pc-linux-gnu
Configuré avec: /build/gcc/src/gcc/configure --prefix=/usr --libdir=/usr/lib
--libexecdir=/usr/lib --mandir=/usr/share/man --infodir=/usr/share/info
--with-pkgversion='Arch Linux 9.2.1+20200130-2'
--with-bugurl=https://bugs.archlinux.org/
--enable-languages=c,c++,ada,fortran,go,lto,objc,obj-c++,d --enable-shared
--enable-threads=posix --with-system-zlib --with-isl --enable-__cxa_atexit
--disable-libunwind-exceptions --enable-clocale=gnu --disable-libstdcxx-pch
--disable-libssp --enable-gnu-unique-object --enable-linker-build-id
--enable-lto --enable-plugin --enable-install-libiberty
--with-linker-hash-style=gnu --enable-gnu-indirect-function --enable-multilib
--disable-werror --enable-checking=release --enable-default-pie
--enable-default-ssp --enable-cet=auto gdc_include_dir=/usr/include/dlang/gdc
Modèle de thread: posix
gcc version 9.2.1 20200130 (Arch Linux 9.2.1+20200130-2)

System:
-------
Archlinux
Linux 5.5.7-arch1-1 #1 SMP PREEMPT Sat, 29 Feb 2020 19:06:02 +0000 x86_64
GNU/Linux

Reply via email to