Uploaded image for project: 'Embedded Software & Tools'
  1. Embedded Software & Tools
  2. EXT_EP-8574

Undefined behavior on lambda capturing constexpr by reference

    XMLWordPrintable

Details

    • Bug
    • Status: New
    • Medium
    • Resolution: Unresolved
    • Code Generation Tools
    • CODEGEN-4002
    • Hide
      ARM_18.1.0.LTS
      MSP430_18.1.0.LTS
      MSP430_20.2.0.LTS
      ARM_18.12.0.LTS
      MSP430_21.6.0.LTS
      MSP430_18.12.0.LTS
      ARM_20.2.0.LTS
      Show
      ARM_18.1.0.LTS MSP430_18.1.0.LTS MSP430_20.2.0.LTS ARM_18.12.0.LTS MSP430_21.6.0.LTS MSP430_18.12.0.LTS ARM_20.2.0.LTS

    Description

      Undefined behavior on lambda capturing constexpr by reference. The C++ standard provides the following example:

      struct S

      { int n; }

      ;
      auto f() {
      S x

      { 1 }

      ;
      constexpr S y

      { 2 }

      ;
      return [&](bool b)

      { return (b ? y : x).n; }

      ;
      }
      auto g = f();
      int m = g(false); // undefined behavior due to access of x.n outside its lifetime
      int n = g(true); // OK, does not access y.n

      gcc-7.2 replaces the reference to y.n with the constant 2, avoiding undefined behavior.

      Attachments

        Activity

          People

            syncuser TI User
            syncuser TI User
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated: