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: Issue with captures

Expert 1635 points

Other Parts Discussed in Thread: TM4C1294NCPDT

Tool/software: TI C/C++ Compiler

I am trying new c++ features not supported with the previous compiler and found and issue that I would like to ask about. The snippet is taken from Josuttis' "The C++ Standard Library", 2nd edition:

#include <iostream>

using namespace std;

int main( void )
{
    int x = 0, y = 42;

    auto qqq = [x, &y]
                {
                    cout << "x: " << x << endl;
                    cout << "y: " << y << endl;

                    ++y;
                };

    x = y = 77;

    qqq();
    qqq();

    cout << "Final y: " << y << endl;
}

It compiles properly, but when I try to debug it I get:

The project configuration is sane though, I can run it by removing the lambda and the local variables from main() and not using any capture argument:

#include <iostream>

using namespace std;

int x = 0, y = 42;

auto qqq = []
            {
                cout << "x: " << x << endl;
                cout << "y: " << y << endl;

                ++y;
            };

int main( void )
{
    x = y = 77;

    qqq();
    qqq();

    cout << "Final y: " << y << endl;
}

Gives:

Since the book is post c++11, is this something that changed with c++14?

Thank you,

Pibe

  • The fact that the debugging information says there is a file named "NO_PSN_FILE" is a bug. This bug does not have a bug tracking number. It should be fixed in the next LTS release. For now, just ignore that message.

    If you hit the "run" button after reaching the first breakpoint in main, does the program then run properly? If not, please describe to us exactly what you see.
  • After hitting RUN, abort() is called:

  • From the stack, we can see that abort was not called while main is on the stack; the program thinks it ran normally, exited main, and the boot code called exit, which on this target always calls abort. So the problem is that you did not get any output when the pragma is defined inside main.
  • What compiler version are you using (it is different than the Code Composer version). What target (ARM, C6000, etc)? What are your command-line options?
  • Make sure you give it a generous heap and stack, at least for testing
  • I am using the CCS v7.4 with TI's compiler version 18.1.1 LTS on a TM4C129 project (using a "Tiva C Series Connected Launchpad"). I had 16KB for heap and 2KB for stack. Doubling the allocated memory has no effect.
  • I cannot reproduce the issue. I need at least the command-line options, which can most easily be seen in the build console after issuing a "build all" command. Alternately, if you could zip and post the whole project here, I could pick out the details.
  • Here it is:

    **** Build of configuration Debug for project Lambdas ****

    /home/pibe/ti/ccsv7/utils/bin/gmake -k -j 8 all -O

    Building file: "../tm4c1294ncpdt_startup_ccs.c"
    Invoking: ARM Compiler
    "/home/pibe/ti/ccsv7/tools/compiler/ti-cgt-arm_18.1.1.LTS/bin/armcl" -mv7M4 --code_state=16 --float_support=FPv4SPD16 -me --include_path="/home/pibe/Development/c++14/Lambdas" --include_path="/home/pibe/ti/ccsv7/tools/compiler/ti-cgt-arm_18.1.1.LTS/include" --define=ccs="ccs" --define=PART_TM4C1294NCPDT -g --rtti --gcc --diag_warning=225 --diag_wrap=off --display_error_number --abi=eabi --preproc_with_compile --preproc_dependency="tm4c1294ncpdt_startup_ccs.d_raw" "../tm4c1294ncpdt_startup_ccs.c"
    Finished building: "../tm4c1294ncpdt_startup_ccs.c"

    Building file: "../main.cpp"
    Invoking: ARM Compiler
    "/home/pibe/ti/ccsv7/tools/compiler/ti-cgt-arm_18.1.1.LTS/bin/armcl" -mv7M4 --code_state=16 --float_support=FPv4SPD16 -me --include_path="/home/pibe/Development/c++14/Lambdas" --include_path="/home/pibe/ti/ccsv7/tools/compiler/ti-cgt-arm_18.1.1.LTS/include" --define=ccs="ccs" --define=PART_TM4C1294NCPDT -g --rtti --gcc --diag_warning=225 --diag_wrap=off --display_error_number --abi=eabi --preproc_with_compile --preproc_dependency="main.d_raw" --exceptions "../main.cpp"
    Finished building: "../main.cpp"

    Building target: "Lambdas.out"
    Invoking: ARM Linker
    "/home/pibe/ti/ccsv7/tools/compiler/ti-cgt-arm_18.1.1.LTS/bin/armcl" -mv7M4 --code_state=16 --float_support=FPv4SPD16 -me --define=ccs="ccs" --define=PART_TM4C1294NCPDT -g --rtti --gcc --diag_warning=225 --diag_wrap=off --display_error_number --abi=eabi -z -m"Lambdas.map" --heap_size=32768 --stack_size=4096 -i"/home/pibe/ti/ccsv7/tools/compiler/ti-cgt-arm_18.1.1.LTS/lib" -i"/home/pibe/ti/ccsv7/tools/compiler/ti-cgt-arm_18.1.1.LTS/include" --reread_libs --diag_wrap=off --display_error_number --warn_sections --xml_link_info="Lambdas_linkInfo.xml" --rom_model -o "Lambdas.out" "./main.obj" "./tm4c1294ncpdt_startup_ccs.obj" "../tm4c1294ncpdt.cmd" -llibc.a
    <Linking>
    Finished building target: "Lambdas.out"


    **** Build Finished ****
  • Well, it runs now. I tried removing support for RTTI (that I enabled for another test) and it worked. The funny thing is that I then re-enabled it and it still kept working. Finally, I set heap/stack to the original values 16K/2K, and it continues working fine:

    The message:

    Can't find a source file at "/home/pibe/Development/c++14/Lambdas/Debug/NO_PSN_FILE"
    Locate the file or edit the source lookup path to include its location.

    is still there though, and the debugger does not stop at the beginning of main(), I need to give it an step for that.

  • I don't know what to tell you... it's disturbing that we don't know what the underlying problem was, but I was never able to reproduce it, so there's really not anything more I can do about it. Should the problem resurface, we definitely want to hear about it.
  • Baffled. I would love to have a time machine and check back, looking over my shoulder.
    I will move this machine to CCS8 soon anyway.

    Thank you.
    Pibe