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

            Bug ID: 105964
           Summary: [12/13 Regression] Return type deduction fails during
                    NTTP use of function dependent on template parameter
           Product: gcc
           Version: 12.1.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: enolan at alumni dot cmu.edu
  Target Milestone: ---

Created attachment 53132
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=53132&action=edit
Proof of concept that reproduces the bug

"It seems that, in a nested template expansion context, for SFINAE purposes,
when filling in default arguments, the compiler is declining to instantiate a
function which has a deduced return type.  Because it declines to instantiate
that function, it can't wind up with a function to implicitly convert to a
pointer-to-function which is a valid NTTP."

However, as can be seen in the attached expanded POC, using an ampersand to
force taking the address of the function when using it as an NTTP causes it to
work again.

Godbolt link: https://godbolt.org/z/j8e6Y5Pq9

Minimal reproduction (godbolt link and attachment contain more context):

struct token {};

struct example {};

template< typename >
struct helper
{
    static constexpr auto c() { return 42; }
};

struct impostor_c
{
    template< typename T, auto= helper< T >::c >
    static example func();
};

example c= impostor_c::func< token >();



> the exact version of gcc

gcc version 12.1.1 20220507 (Red Hat 12.1.1-1) (GCC)

> the system type

Fedora release 37 (rawhide)

> the options given when GCC was configured/built

Configured with: ../configure --enable-bootstrap
--enable-languages=c,c++,fortran,objc,obj-c++,ada,go,d,lto --prefix=/usr
--mandir=/usr/share/man --infodir=/usr/share/info
--with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-shared
--enable-threads=posix --enable-checking=release --enable-multilib
--with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions
--enable-gnu-unique-object --enable-linker-build-id
--with-gcc-major-version-only --enable-libstdcxx-backtrace
--with-linker-hash-style=gnu --enable-plugin --enable-initfini-array
--with-isl=/builddir/build/BUILD/gcc-12.1.1-20220507/obj-x86_64-redhat-linux/isl-install
--enable-offload-targets=nvptx-none --without-cuda-driver
--enable-offload-defaulted --enable-gnu-indirect-function --enable-cet
--with-tune=generic --with-arch_32=i686 --build=x86_64-redhat-linux
--with-build-config=bootstrap-lto --enable-link-serialization=1

> the complete command line that triggers the bug

g++ -std=c++17 poc.cpp

> the compiler output

poc.cpp:55:37: error: no matching function for call to
‘impostor_c::func<token>()’
   55 | example c= impostor_c::func< token >();
      |            ~~~~~~~~~~~~~~~~~~~~~~~~~^~
poc.cpp:28:20: note: candidate: ‘template<class T, auto <anonymous> > static
example impostor_c::func()’
   28 |     static example func();
      |                    ^~~~
poc.cpp:28:20: note:   template argument deduction/substitution failed:

Reply via email to