Somebody in c.l.c++.m[1] dug out an overlooked clause in 12.2/5
[class.temporary], namely that "A temporary bound to a reference member in a
constructor's ctor-initializer (12.6.2) persists until the constructor exists"

The following piece of code should therefore print:

===
A() 
A()
B()
~A()
~A()
main
===

however, all tested versions (gcc-3.3.6, gcc-4.0.3, gcc-4.1.0) print: 

==
A()
~A()
A()
~A()
B()
main
==

// begin example
extern "C" int puts(const char*);
struct A
{
  A() { puts("A()"); }
  ~A() { puts("~A()"); }
}; 

struct B
{
  const A &a1; 
  const A &a2; 
  B() : a1(A()),a2(A()) { puts("B()"); }
}; 

int main()
{
  B b; 
  puts("main"); 
}
// end example

References: 
[1] Message-ID:<[EMAIL PROTECTED]>


-- 
           Summary: violation of [class.temporary]/5
           Product: gcc
           Version: 4.0.3
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: marco at technoboredom dot net
 GCC build triplet: i586-suse-linux
  GCC host triplet: i586-suse-linux
GCC target triplet: i586-suse-linux


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=26714

Reply via email to