[Bug c++/102338] Recursive noexcept specification inside class/struct

jergussuja at gmail dot com gcc-bugzilla@gcc.gnu.org
Wed Sep 15 07:28:34 GMT 2021


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

--- Comment #4 from Jerguš Suja <jergussuja at gmail dot com> ---
gcc version 9.3.0

x86_64-linux-gnu

Configured with: ../src/configure -v --with-pkgversion='Ubuntu 9.3.0-10ubuntu2'
--with-bugurl=file:///usr/share/doc/gcc-9/README.Bugs
--enable-languages=c,ada,c++,go,brig,d,fortran,objc,obj-c++,gm2 --prefix=/usr
--with-gcc-major-version-only --program-suffix=-9
--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-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 --with-target-system-zlib=auto
--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,hsa
--without-cuda-driver --enable-checking=release --build=x86_64-linux-gnu
--host=x86_64-linux-gnu --target=x86_64-linux-gnu

Code that trigger compilation failed:

struct S {

    template<typename T>
    static auto f(T && t) noexcept {
        return true;
    }

    template<typename T, typename... Ts>
    static auto f(T && t, Ts && ... ts) noexcept(noexcept(f(ts...))) {
        return f(ts...);
    }

};

int main() {
    S::f(true, 0, 5u);
    return 0;
}

Compiler error:

bug.cpp: In instantiation of ‘static auto S::f(T&&, Ts&& ...) [with T = bool;
Ts = {int, unsigned int}]’:
bug.cpp:16:21:   required from here
bug.cpp:9:60: error: no matching function for call to ‘S::f(int&, unsigned
int&)’
    9 |     static auto f(T && t, Ts && ... ts) noexcept(noexcept(f(ts...))) {
      |                                                           ~^~~~~~~
bug.cpp:4:17: note: candidate: ‘template<class T> static auto S::f(T&&)’
    4 |     static auto f(T && t) noexcept {
      |                 ^
bug.cpp:4:17: note:   template argument deduction/substitution failed:
bug.cpp:9:60: note:   candidate expects 1 argument, 2 provided
    9 |     static auto f(T && t, Ts && ... ts) noexcept(noexcept(f(ts...))) {
      |                                                           ~^~~~~~~

GCC version 7.5 compile this, but version 8 and more does not. If I declare
function 'f' in scope of class or struct, it should be visible everywhere
inside class/struct scope. Also in noexcept specifier (it should not matter if
it is recursive call). MSVC v19.28 and Clang 12.0.1 accept this and compile
this code.


More information about the Gcc-bugs mailing list