This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Compiler: TI C++ Compiler does not support conversion from std::function to pointer

Other Parts Discussed in Thread: CC2650

Tool/software: TI C/C++ Compiler

Hi all,

When I tried to use std::function and convert it to pointer:

  const std::function<bStatus_t(uint16 connHandle,
                                gattAttribute_t *pAttr,
                                uint8 *pValue,
                                uint16 *pLen,
                                uint16 offset,
                                uint16 maxLen,
                                uint8 method)>
  kReadAttrCB = std::bind(&Service::ReadAttrCB, this,
                          std::placeholders::_1,
                          std::placeholders::_2,
                          std::placeholders::_3,
                          std::placeholders::_4,
                          std::placeholders::_5,
                          std::placeholders::_6,
                          std::placeholders::_7);

  auto pf = kReadAttrCB.target<bStatus_t(*)( uint16 connHandle, gattAttribute_t *pAttr,
          uint8 *pValue, uint16 *pLen, uint16 offset,
          uint16 maxLen, uint8 method )>();

I have got the following error:

"../Profiles/service.cpp", line 243: error #136: class "std::__2::function<bStatus_t (uint16, gattAttribute_t *, uint8 *, uint16 *, uint16, uint16, uint8)>" has no member "target"

Is it a bug of compiler ?

  • For the source file which gets this diagnostic, please follow the directions in the article How to Submit a Compiler Test Case.

    Thanks and regards,

    -George

  • class MyCustomClass {
    public:
        MyCustomClass() {
          int (*pg)(int) = [this] (int i) {
              this->ReadAttrCB(1);
              return 1;
          };
        }
    
        int ReadAttrCB(int i) {
            return i;
        }
    };
    

    Build: "/HomeDir/ti/ccsv8/ccsv8/tools/compiler/ti-cgt-arm_18.1.5.LTS/bin/armcl" --cmd_file="/HomeDir/ti/simplelink/ble_sdk_2_02_01_18/src/config/build_components.opt" --cmd_file="/ProjectDir/project_zero_stack_cc2650/TOOLS/build_config.opt" --cmd_file="/ProjectDir/project_zero_stack_cc2650/TOOLS/ccs_compiler_defines.bcfg"  -mv7M3 --code_state=16 -me -O4 --opt_for_speed=0 --include_path="/HomeDir/ti/simplelink/ble_sdk_2_02_01_18/src/target" --include_path="/ProjectDir/project_zero_app_cc2650launchxl" --include_path="/ProjectDir/project_zero_app_cc2650launchxl/Profiles" --include_path="/ProjectDir/project_zero_app_cc2650launchxl/Application" --include_path="/ProjectDir/project_zero_app_cc2650launchxl/ICallBLE" --include_path="/ProjectDir/project_zero_app_cc2650launchxl/Startup" --include_path="/ProjectDir/project_zero_app_cc2650launchxl/Board" --include_path="/HomeDir/ti/simplelink_academy_01_11_00_0000/modules/projects/support_files/Components/uart_log" --include_path="/HomeDir/ti/simplelink/ble_sdk_2_02_01_18/src/examples/simple_peripheral/cc26xx/app" --include_path="/HomeDir/ti/simplelink/ble_sdk_2_02_01_18/src/inc" --include_path="/HomeDir/ti/simplelink/ble_sdk_2_02_01_18/src/icall/inc" --include_path="/HomeDir/ti/simplelink/ble_sdk_2_02_01_18/src/profiles/roles/cc26xx" --include_path="/HomeDir/ti/simplelink/ble_sdk_2_02_01_18/src/profiles/roles" --include_path="/HomeDir/ti/simplelink/ble_sdk_2_02_01_18/src/profiles/dev_info" --include_path="/HomeDir/ti/simplelink/ble_sdk_2_02_01_18/src/profiles/simple_profile/cc26xx" --include_path="/HomeDir/ti/simplelink/ble_sdk_2_02_01_18/src/profiles/simple_profile" --include_path="/HomeDir/ti/simplelink/ble_sdk_2_02_01_18/src/common/cc26xx" --include_path="/HomeDir/ti/simplelink/ble_sdk_2_02_01_18/src/components/heapmgr" --include_path="/HomeDir/ti/simplelink/ble_sdk_2_02_01_18/src/controller/cc26xx/inc" --include_path="/HomeDir/ti/simplelink/ble_sdk_2_02_01_18/src/components/hal/src/target/_common" --include_path="/HomeDir/ti/simplelink/ble_sdk_2_02_01_18/src/components/hal/src/target" --include_path="/HomeDir/ti/simplelink/ble_sdk_2_02_01_18/src/components/hal/src/target/_common/cc26xx" --include_path="/HomeDir/ti/simplelink/ble_sdk_2_02_01_18/src/components/hal/src/inc" --include_path="/HomeDir/ti/simplelink/ble_sdk_2_02_01_18/src/components/osal/src/inc" --include_path="/HomeDir/ti/simplelink/ble_sdk_2_02_01_18/src/components/services/src/sdata" --include_path="/HomeDir/ti/simplelink/ble_sdk_2_02_01_18/src/components/services/src/saddr" --include_path="/HomeDir/ti/simplelink/ble_sdk_2_02_01_18/src/components/icall/src/inc" --include_path="/HomeDir/ti/tirtos_cc13xx_cc26xx_2_20_01_08/products/cc26xxware_2_24_02_17393" --include_path="/HomeDir/ti/ccsv8/ccsv8/tools/compiler/ti-cgt-arm_18.1.5.LTS/include" --define=CC2650_LAUNCHXL --define=USE_ICALL --define=POWER_SAVING --define=SBP_TASK_STACK_SIZE=700 --define=GAPROLE_TASK_STACK_SIZE=520 --define=HEAPMGR_SIZE=0 --define=Display_DISABLE_ALL --define=BOARD_DISPLAY_EXCLUDE_UART --define=xBOARD_DISPLAY_EXCLUDE_LCD --define=ICALL_MAX_NUM_TASKS=3 --define=ICALL_MAX_NUM_ENTITIES=6 --define=xdc_runtime_Assert_DISABLE_ALL --define=Xxdc_runtime_Log_DISABLE_ALL --define=MAX_NUM_BLE_CONNS=1 --define=CC26XX --define=xdc_FILE="\"test_lambda.cpp\"" --define=UARTLOG_NUM_EVT_BUF=32 -g --c99 --gcc --preproc_with_comment --preproc_with_compile --diag_warning=225 --diag_warning=255 --diag_wrap=off --display_error_number --gen_func_subsections=on --abi=eabi --obj_directory="Profiles" --cmd_file="configPkg/compiler.opt" "../Profiles/test_lambda.cpp"

    Compiler: TI ARM 18.1.5.LTS

    This issue I have reproduced with the following simple source file:

    class MyCustomClass {
    public:
        MyCustomClass() {
          int (*pg)(int) = [this] (int i) {
              this->ReadAttrCB(1);
              return 1;
          };
        }
    
        int ReadAttrCB(int i) {
            return i;
        }
    };
    

  • Hi again,

    Maybe you know how to change compiler easily on GCC ARM ?
    When I change compiler to GCC ARM I lose all compiler options, include directories ...

    Is there an easy way to switch between compilers ?
  • Denis Kotov said:
    This issue I have reproduced with the following simple source file:

    Thank you for the test case.  However, when I build it, I do not get the same diagnostic as you show in the first post.  I see this ...

    "file.cpp", line 4: error #415: no suitable conversion function from "lambda [](int)->int" to "int (*)(int)" exists
    1 error detected in the compilation of "file.cpp".

    I think it is best if I reproduce the exact same error.  For the source file which gets the original error, please submit the preprocessed file described in the article How to Submit a Compiler Test Case.

    Thanks and regards,

    -George

  • TestSample.pp.txt

    Build: "/HomeDir/ti/ccsv8/tools/compiler/ti-cgt-arm_18.1.5.LTS/bin/armcl" --cmd_file="/HomeDir/ti/simplelink/ble_sdk_2_02_01_18/src/config/build_components.opt" --cmd_file="/ProjectDirproject_zero_stack_cc2650/TOOLS/build_config.opt" --cmd_file="/ProjectDirproject_zero_stack_cc2650/TOOLS/ccs_compiler_defines.bcfg"  -mv7M3 --code_state=16 -me -O4 --opt_for_speed=0 --include_path="/HomeDir/ti/simplelink/ble_sdk_2_02_01_18/src/target" --include_path="/ProjectDirproject_zero_app_cc2650launchxl" --include_path="/ProjectDirproject_zero_app_cc2650launchxl/Profiles" --include_path="/ProjectDirproject_zero_app_cc2650launchxl/Application" --include_path="/ProjectDirproject_zero_app_cc2650launchxl/ICallBLE" --include_path="/ProjectDirproject_zero_app_cc2650launchxl/Startup" --include_path="/ProjectDirproject_zero_app_cc2650launchxl/Board" --include_path="/HomeDir/ti/simplelink_academy_01_11_00_0000/modules/projects/support_files/Components/uart_log" --include_path="/HomeDir/ti/simplelink/ble_sdk_2_02_01_18/src/examples/simple_peripheral/cc26xx/app" --include_path="/HomeDir/ti/simplelink/ble_sdk_2_02_01_18/src/inc" --include_path="/HomeDir/ti/simplelink/ble_sdk_2_02_01_18/src/icall/inc" --include_path="/HomeDir/ti/simplelink/ble_sdk_2_02_01_18/src/profiles/roles/cc26xx" --include_path="/HomeDir/ti/simplelink/ble_sdk_2_02_01_18/src/profiles/roles" --include_path="/HomeDir/ti/simplelink/ble_sdk_2_02_01_18/src/profiles/dev_info" --include_path="/HomeDir/ti/simplelink/ble_sdk_2_02_01_18/src/profiles/simple_profile/cc26xx" --include_path="/HomeDir/ti/simplelink/ble_sdk_2_02_01_18/src/profiles/simple_profile" --include_path="/HomeDir/ti/simplelink/ble_sdk_2_02_01_18/src/common/cc26xx" --include_path="/HomeDir/ti/simplelink/ble_sdk_2_02_01_18/src/components/heapmgr" --include_path="/HomeDir/ti/simplelink/ble_sdk_2_02_01_18/src/controller/cc26xx/inc" --include_path="/HomeDir/ti/simplelink/ble_sdk_2_02_01_18/src/components/hal/src/target/_common" --include_path="/HomeDir/ti/simplelink/ble_sdk_2_02_01_18/src/components/hal/src/target" --include_path="/HomeDir/ti/simplelink/ble_sdk_2_02_01_18/src/components/hal/src/target/_common/cc26xx" --include_path="/HomeDir/ti/simplelink/ble_sdk_2_02_01_18/src/components/hal/src/inc" --include_path="/HomeDir/ti/simplelink/ble_sdk_2_02_01_18/src/components/osal/src/inc" --include_path="/HomeDir/ti/simplelink/ble_sdk_2_02_01_18/src/components/services/src/sdata" --include_path="/HomeDir/ti/simplelink/ble_sdk_2_02_01_18/src/components/services/src/saddr" --include_path="/HomeDir/ti/simplelink/ble_sdk_2_02_01_18/src/components/icall/src/inc" --include_path="/HomeDir/ti/tirtos_cc13xx_cc26xx_2_20_01_08/products/cc26xxware_2_24_02_17393" --include_path="/HomeDir/ti/ccsv8/tools/compiler/ti-cgt-arm_18.1.5.LTS/include" --define=CC2650_LAUNCHXL --define=USE_ICALL --define=POWER_SAVING --define=SBP_TASK_STACK_SIZE=700 --define=GAPROLE_TASK_STACK_SIZE=520 --define=HEAPMGR_SIZE=0 --define=Display_DISABLE_ALL --define=BOARD_DISPLAY_EXCLUDE_UART --define=xBOARD_DISPLAY_EXCLUDE_LCD --define=ICALL_MAX_NUM_TASKS=3 --define=ICALL_MAX_NUM_ENTITIES=6 --define=xdc_runtime_Assert_DISABLE_ALL --define=Xxdc_runtime_Log_DISABLE_ALL --define=MAX_NUM_BLE_CONNS=1 --define=CC26XX --define=xdc_FILE="\"TestSample.cpp\"" --define=UARTLOG_NUM_EVT_BUF=32 -g --c99 --gcc --preproc_with_comment --preproc_with_compile --diag_warning=225 --diag_warning=255 --diag_wrap=off --display_error_number --gen_func_subsections=on --abi=eabi --obj_directory="Profiles" --cmd_file="configPkg/compiler.opt" "../Profiles/TestSample.cpp"

    Compiler: TI ARM 18.1.5.LTS

    This issue I have reproduced again with the following simple source file:

    #include <functional>
    
    class MyCustomClass {
    public:
        MyCustomClass() {
            std::function<int(int)> readAttrCB =
                    std::bind(&MyCustomClass::ReadAttrCB,
                              this,
                              std::placeholders::_1);
    
          int (*pg)(int) = readAttrCB.target<int(*)(int)>();
        }
    
        int ReadAttrCB(int i) {
            return i;
        }
    };
    

  • The C++14 standard, in 20.9.11.2.5, paragraph 3, states that the return value of the function::target function is a pointer to the stored function target if " target_type() == typeid(T)", and a null pointer otherwise.

    The TI compiler by default does not generate runtime type information, which is required for the typeid operator. Thus, this function is not provided in those modes.

    The following link will show that when runtime type information is turned off, both gcc and clang give the same error on your code sample. You can enable this in the TI compiler through either the -rtti or --exceptions options.

    https://godbolt.org/z/YzTxhn

  • Thank you, James Nagurne for support !!