[Bug c++/85825] New: Incorrect selection of method in template<auto> class specialization.

christosstratopoulos1 at gmail dot com gcc-bugzilla@gcc.gnu.org
Thu May 17 22:58:00 GMT 2018


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

            Bug ID: 85825
           Summary: Incorrect selection of method in template<auto> class
                    specialization.
           Product: gcc
           Version: 7.3.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: christosstratopoulos1 at gmail dot com
  Target Milestone: ---

Created attachment 44144
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=44144&action=edit
The output of compilation with -save-temps

Here is the full sample code that causes the issue:

#include <cassert>

enum class Frac : unsigned { half = 2, quarter = 4 };

enum class Whole : unsigned { two = 2, five = 5 };

template<unsigned, auto enumVal>
class A;

template<unsigned m, Frac f>
class A<m, f> {
public:
    constexpr double val() const noexcept { return 2.0; }
};

template<unsigned m, Whole w>
class A<m, w> {
public:
    constexpr double val() const noexcept { return 1.0; }
};

int main()
{   
    auto frac4 = A<100, Frac::quarter>{}.val();
    auto whole5 = A<100, Whole::five>{}.val();

    assert(frac4 != whole5); // passes

    auto frac2 = A<100, Frac::half>{}.val();
    auto whole2 = A<100, Whole::two>{}.val();

    assert(frac2 != whole2); // fails on g++ 7.x, fine on 8.1, 9 HEAD
}

This is a heavily reduced version of something I encountered at work today,
originally when compiling some code for g++-7.3.0 on a Bash subsystem of a
windows 10 install. I've attached a .ii for that file, and marked this as a
g++-7.3 bug, but testing on wandbox.org has shown this holds for other g++ 7.x,
but seems fine on 8 and 9.

I first ran into this as a compile-time error when trying to compile with the
windows version of clang 6, which reports "definition with same mangled name as
other definition". I have not been able to repro this with online (Linux)
versions of clang.

Here is the output of g++-7 -v:

Using built-in specs.
COLLECT_GCC=g++-7
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/7/lto-wrapper
OFFLOAD_TARGET_NAMES=nvptx-none
OFFLOAD_TARGET_DEFAULT=1
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu
7.3.0-16ubuntu3~16.04.1' --with-bugurl=file:///usr/share/doc/gcc-7/README.Bugs
--enable-languages=c,ada,c++,go,brig,d,fortran,objc,obj-c++ --prefix=/usr
--with-gcc-major-version-only --with-as=/usr/bin/x86_64-linux-gnu-as
--with-ld=/usr/bin/x86_64-linux-gnu-ld --program-suffix=-7
--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 --with-sysroot=/ --enable-clocale=gnu
--enable-libstdcxx-debug --enable-libstdcxx-time=yes
--with-default-libstdcxx-abi=new --enable-gnu-unique-object
--disable-vtable-verify --enable-libmpx --enable-plugin --with-system-zlib
--with-target-system-zlib --enable-objc-gc=auto --enable-multiarch
--disable-werror --with-arch-32=i686 --with-abi=m64
--with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic
--enable-offload-targets=nvptx-none --without-cuda-driver
--enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu
--target=x86_64-linux-gnu
Thread model: posix
gcc version 7.3.0 (Ubuntu 7.3.0-16ubuntu3~16.04.1)

and the command line invocation is

g++-7 -std=c++17 gcc_bug_simple.cpp && ./a.out


More information about the Gcc-bugs mailing list