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

            Bug ID: 91798
           Summary: Compiler rejects code due to template specialization
                    of auto parameter value.
           Product: gcc
           Version: 8.1.0
               URL: https://wandbox.org/permlink/YuXR4WMYflBZTW4m
            Status: UNCONFIRMED
          Keywords: rejects-valid
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: 94sarkar.anirban at gmail dot com
  Target Milestone: ---

G++ rejects the following code that runs fine on Clang and MSVC.


//Get type parameter at given index.
template<auto, class...>
struct param;

template<auto i, class t, class ...ts>
struct param<i, t, ts...>
{
    static_assert(i > 0, "Index into parameter pack cannot be negative!");

    using type = typename param<i - 1, ts...>::type;
};

template<class t, class ...ts>
struct param<0, t, ts...>
{
    using type = t;
};

int main()
{
    typename param<0u, char, int, float>::type x = 'a';
    static_cast<void>(x);
}
//======================================================== end example


When compiled with "g++ example.cpp -Wall -Wextra -std=c++17 -pedantic-errors",
the compiler outputs:
example.cpp: In instantiation of 'struct param<0, char, int, float>':
example.cpp:21:41:   required from here
example.cpp:8:21: error: static assertion failed: Index into parameter pack
cannot be negative!
     static_assert(i > 0, "Index into parameter pack cannot be negative!");
                   ~~^~~
example.cpp: In instantiation of 'struct param<4294967294, float>':
example.cpp:10:52:   recursively required from 'struct param<4294967295, int,
float>'
example.cpp:10:52:   required from 'struct param<0, char, int, float>'
example.cpp:21:41:   required from here
example.cpp:10:52: error: invalid use of incomplete type 'struct
param<4294967293>'
     using type = typename param<i - 1, ts...>::type;
                                                    ^
example.cpp:3:8: note: declaration of 'struct param<4294967293>'
 struct param;
        ^~~~~
example.cpp: In function 'int main()':
example.cpp:21:43: error: invalid combination of multiple type-specifiers
     typename param<0u, char, int, float>::type x = 'a';
                                           ^~~~


I use a G++ build of MinGW-W64 whose build options from "g++ -v" are:
Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=D:/Software\ Development\
Kits/C++/MinGW/bin/../libexec/gcc/
x86_64-w64-mingw32/8.1.0/lto-wrapper.exe
Target: x86_64-w64-mingw32
Configured with: ../../../src/gcc-8.1.0/configure --host=x86_64-w64-mingw32
--bu
ild=x86_64-w64-mingw32 --target=x86_64-w64-mingw32 --prefix=/mingw64
--with-sysr
oot=/c/mingw810/x86_64-810-win32-seh-rt_v6-rev0/mingw64 --enable-shared
--enable
-static --disable-multilib --enable-languages=c,c++,fortran,lto
--enable-libstdc
xx-time=yes --enable-threads=win32 --enable-libgomp --enable-libatomic
--enable-
lto --enable-graphite --enable-checking=release --enable-fully-dynamic-string
--
enable-version-specific-runtime-libs --disable-libstdcxx-pch
--disable-libstdcxx
-debug --enable-bootstrap --disable-rpath --disable-win32-registry
--disable-nls
 --disable-werror --disable-symvers --with-gnu-as --with-gnu-ld
--with-arch=noco
na --with-tune=core2 --with-libiconv --with-system-zlib
--with-gmp=/c/mingw810/p
rerequisites/x86_64-w64-mingw32-static
--with-mpfr=/c/mingw810/prerequisites/x86
_64-w64-mingw32-static
--with-mpc=/c/mingw810/prerequisites/x86_64-w64-mingw32-s
tatic --with-isl=/c/mingw810/prerequisites/x86_64-w64-mingw32-static
--with-pkgv
ersion='x86_64-win32-seh-rev0, Built by MinGW-W64 project'
--with-bugurl=https:/
/sourceforge.net/projects/mingw-w64 CFLAGS='-O2 -pipe -fno-ident
-I/c/mingw810/x
86_64-810-win32-seh-rt_v6-rev0/mingw64/opt/include
-I/c/mingw810/prerequisites/x
86_64-zlib-static/include
-I/c/mingw810/prerequisites/x86_64-w64-mingw32-static/
include' CXXFLAGS='-O2 -pipe -fno-ident
-I/c/mingw810/x86_64-810-win32-seh-rt_v6
-rev0/mingw64/opt/include
-I/c/mingw810/prerequisites/x86_64-zlib-static/include
 -I/c/mingw810/prerequisites/x86_64-w64-mingw32-static/include' CPPFLAGS='
-I/c/
mingw810/x86_64-810-win32-seh-rt_v6-rev0/mingw64/opt/include
-I/c/mingw810/prere
quisites/x86_64-zlib-static/include
-I/c/mingw810/prerequisites/x86_64-w64-mingw
32-static/include' LDFLAGS='-pipe -fno-ident
-L/c/mingw810/x86_64-810-win32-seh-
rt_v6-rev0/mingw64/opt/lib -L/c/mingw810/prerequisites/x86_64-zlib-static/lib
-L
/c/mingw810/prerequisites/x86_64-w64-mingw32-static/lib '
Thread model: win32
gcc version 8.1.0 (x86_64-win32-seh-rev0, Built by MinGW-W64 project)


The same error is reported on all versions of GCC above 7.3.0 as present on
https://wandbox.org/.

Reply via email to