Is Initializing a constant lvalue reference from an rvalue undefined?

Viewed 39

I have this example:

  #include<iostream>
  using namespace std;

  struct Foo
  {
      int const& rci; 
      Foo(int const& x) : rci(x){}
  };

  int main()
  {
      Foo f(7);
      cout << f.rci << endl;
  
  }

I've tried this code on many compilers and it works fine printing 7 because the reference member is bound to a temporary but running it on the application decoder it gives me value 0 rather than 7.

Is this a problem in the application Decoder or in my code?

0 Answers
Related