Undefined behavior on lambda capturing constexpr by reference

XMLWordPrintable

    • Type: Bug
    • Resolution: Unresolved
    • Priority: Medium
    • 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

      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.

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

              Created:
              Updated:

                Connection: Intermediate to External PROD System
                EXTSYNC-1077 - Undefined behavior on lambda captur...
                SYNCHRONIZED
                • Last Sync Date: