title: Taking address of temporary - workaround needed
body: <p>I am facing a GCC warning that I want to fix. Basically I am passing to a method a pointer to a local variable, which in my case is perfectly OK. I understand why the compiler tells me that this is a potential problem, but in my case this is OK.</p>
  
  <p>How can I workaround it, on a local space? Passing <code>-fpermissive</code> when compiling will make me fail to find future problems. I want to fix this specific problem, or workaround it.</p>
  
  <p>Code is available here:</p>
  
  <pre><code>#include &lt;cstdio&gt;
  
  class Integer{
  public:
      Integer(int i ){ v = i; };
      int value(){ return v; };
  private:
      int v;
  };
  
  int foo(Integer *i);
  
  int main()
  {
      foo( &amp;Integer(12) );
  }
  
  int foo(Integer *i)
  {
      std::printf("Integer = %d\n", i-&gt;value());
  }
  </code></pre>
  
  <p>And compilation gives me:</p>
  
  <pre><code>$ g++ test-reference.cpp -O test-reference
  test-reference.cpp: In function ‘int main()’:
  test-reference.cpp:15:18: error: taking address of temporary [-fpermissive]
  
  $ g++ --version
  g++ (Ubuntu/Linaro 4.6.3-1ubuntu3) 4.6.3
  Copyright (C) 2011 Free Software Foundation, Inc.
  This is free software; see the source for copying conditions.  There is NO
  warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  </code></pre>
  
  <p>EDIT:</p>
  
  <p>Using <code>const</code> (as in making <code>foo</code> take a const pointer, and marking <code>value()</code> as const) gives the same error.</p>