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

            Bug ID: 121611
           Summary: Template argument deduction fails with type conversion
                    error for consecutive THUMB functions
           Product: gcc
           Version: 14.3.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: tiagolsilva14 at gmail dot com
  Target Milestone: ---

Created attachment 62157
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=62157&action=edit
The minimal preprocessed source to reproduce the issue.

In ARM GCC 14.3.1, template argument deduction breaks when you pass a function
pointer to a template if the function declared right before it is marked as
THUMB.

Minimal code that causes the issue:
// Template that triggers the bug
template<class Ret, class Arg>
void func_ptr_template(Ret(*func)(Arg)) {
    // Empty implementation
}

class SomeClass;

[[gnu::target("thumb")]] int func_2(SomeClass* obj) { return 0; }

// void placeholder() {} // <-- This makes the compilation succeed

// This one fails in the template if the function before it is THUMB
// Regardless of func_1 being THUMB or not
[[gnu::target("thumb")]] int func_1(SomeClass* obj) { return 0; }

int main() {
    func_ptr_template(func_1); // ERROR: template deduction fails
    return 0;
}

Command used to compile:
arm-none-eabi-gcc -v -save-temps example.cpp

Reproducible on the following version:

Using built-in specs.
COLLECT_GCC=arm-none-eabi-gcc
COLLECT_LTO_WRAPPER=/home/tiago/Programs/arm-gnu-toolchain-14.3.rel1-x86_64-arm-none-eabi/bin/../libexec/gcc/arm-none-eabi/14.3.1/lto-wrapper
Target: arm-none-eabi
Configured with: /data/jenkins/workspace/GNU-toolchain/arm-14/src/gcc/configure
--target=arm-none-eabi
--prefix=/data/jenkins/workspace/GNU-toolchain/arm-14/build-arm-none-eabi/install
--with-gmp=/data/jenkins/workspace/GNU-toolchain/arm-14/build-arm-none-eabi/host-tools
--with-mpfr=/data/jenkins/workspace/GNU-toolchain/arm-14/build-arm-none-eabi/host-tools
--with-mpc=/data/jenkins/workspace/GNU-toolchain/arm-14/build-arm-none-eabi/host-tools
--with-isl=/data/jenkins/workspace/GNU-toolchain/arm-14/build-arm-none-eabi/host-tools
--disable-shared --disable-nls --disable-threads --disable-tls
--enable-checking=release --enable-languages=c,c++,fortran --with-newlib
--with-gnu-as --with-headers=yes --with-gnu-ld
--with-native-system-header-dir=/include
--with-sysroot=/data/jenkins/workspace/GNU-toolchain/arm-14/build-arm-none-eabi/install/arm-none-eabi
--with-bugurl=https://bugs.linaro.org/ --with-multilib-list=aprofile,rmprofile
--with-pkgversion='Arm GNU Toolchain 14.3.Rel1 (Build arm-14.174)'
Thread model: single
Supported LTO compression algorithms: zlib zstd
gcc version 14.3.1 20250623 (Arm GNU Toolchain 14.3.Rel1 (Build arm-14.174))

Reply via email to